2009-11-19 84 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"