2009-11-19 83 views
1

我有一个批处理文件,用于检查我的网站是否对Ping进行了反应。 如果网站没有反应,脚本会将输出写入文本文件。将Windows批处理文件翻译成Linux shell脚本

我想在Linux系统上使用同一种脚本。

任何人都可以帮我翻译代码,以便我可以在Linux shell上使用它吗?

set list=domains.txt 
If "%list%" =="" GoTo EXIT 
for /f "eol=; tokens=1*" %%i in (%list%) do ping -n 1 -w 1 www.%%i >> no-response.txt; 

非常感谢

回答

1

惟独1ms的超时:

while read DOMAIN 
do 
    ping -c 1 -W 1 "www.${DOMAIN}" >dev/null || echo "${DOMAIN}" >>"no-response.txt" 
done <"domains.txt" 

(domains.txt可能需要Unix行结尾)

+0

感谢道格拉斯, 可能被ping域列在“无response.txt”文件。有没有办法让域名不响应? – 2009-11-19 15:06:36

+0

Windows ping不成功输出吗? – 2009-11-20 09:57:25

1

更新。这将评估ping命令是否成功。

#!/bin/sh 

list=`cat domains.txt` 
for domain in $list ; do 
    ping -c 1 -W 1 www.$domain 
    if [ "$?" -ne "0" ] ; then 
    echo $domain >> no-response.txt 
    fi 
done 
0
while read domain 
do 
ping -c1 "$domain" -W2 1> /dev/null || echo "No response: $domain" >> no-response.txt 
done < "file"