views:

67

answers:

3

I have a batch file that I use to check whether my sites react to a ping. If a site doesn't react, the script writes the output into a text file.

I wanted to use the same kind of script on a Linux system.

Can anyone help me translating the code so that I can use it on a 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;

Thanks a lot

+1  A: 

Everything except the timeout of 1ms:

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

(domains.txt might need Unix line endings)

Douglas Leeder
Thanks Douglas,the domains that could be pinged are listed in the "no-response.txt" file. Is there a way to get the domains that don't respond.
Jennifer Weinberg
Does Windows ping not output on success???
Douglas Leeder
+1  A: 

Updated. This one will evaluate whether the ping command was successful or not.

#!/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
Jeff
A: 
while read domain
do
 ping -c1 "$domain" -W2 1> /dev/null || echo "No response: $domain" >> no-response.txt
done < "file"
ghostdog74