ping alive host in network
hi guys
i m trying to do a shellscript to find out any alive host in the network Code:
for n in {1-254}; do ty |
remove the space after "host=", and change {1-254} to {1..254}. or use a tool designed for the job, like fping
|
oh thank you so much, DAT space
also, i was trying ..like save the output into another file with $date, so that they will not overwrite each other everytime i run the script any helps? thx |
NOW=$(date +"%d-%m-%Y")
LOGFILE="$NOW.log" for n in {1..254}; do host=192.168.1.$n ping -c2 $host if [$?=0];then echo "$host is up" >> $LOGFILE else echo "$host is down" >> $LOGFILE fi done |
Hmm, bit overkill I'd say.
Code:
for n in {1..254}; do |
I'd change this line
Code:
if [$?=0];then |
Quote:
|
hi thank you guys!
the $? actually represent as a what |
@acid_kewpie: yeah, I was surprised; actually re-read that a few times to make sure before I posted ;)
@slowerogue: $? is that final exit status of the last ie preceding cmd run. Generally its 0 (zero) if ok, anything else is an error, but the actual error value and meaning is cmd dependent. I recommend you bookmark/read http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
All times are GMT -5. The time now is 04:40 AM. |