shell - Bash Script to check host status -


i have file 1.txt has 1 line per ip or host, ie:

yahoo.com 8.8.8.8 

i trying write bash script parse through text file see if host or not. need store status of host on namesake text file , loop process indefinitely.

here progress far, somehow doesnt seem working, not sure why.

while read ip ;         ping -c 1 $ip | grep -e -o '[0-9]+ received' | cut -f1 -d' ' > $ip-status  $status=$(cat $ip-status) if [ $status = "1" ];                 echo "$ip up" fi echo "$ip down!" done < 1.txt 

any appreciated.

why not take different approach , this:

while true;       in $(cat test);                dig +short +timeout=2 +tries=3 "$i" &&          echo "$i" ||          echo "$i" not responding;          sleep 2;       done;  done; 

here tested output:

$ while true; in $(cat test); dig +short +timeout=2 "$i" && echo host "$i" || echo host "$i" not responding; sleep 2; done; done 216.58.218.206 host google.com 98.138.253.109 98.139.183.24 206.190.36.45 host yahoo.com 216.58.218.206 host google.com 206.190.36.45 98.138.253.109 98.139.183.24 host yahoo.com 216.58.218.206 host google.com 98.139.183.24 206.190.36.45 98.138.253.109 host yahoo.com 

if not want ips sent standard output /dev/null.

please vote if found helpful.

edit:

i forgot show test file:

$ cat test google.com yahoo.com $ 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -