Hi All,
I am trying to write a shell script to ping a set of machines and generate a report.
Here is the script I have written till now:
Code:
#!/bin/bash/
x=`cat machines.txt|wc -l`
for ((i=1;i<=$x;i++))
do
machine=`sed -n "${i}p" machines.txt`
echo $machine
command=`(ping -c 4 $machine) >> output.txt`
$command
if [ $? -eq 0 ]
then
echo -e "Machine is up"
fi
done
Still lots has to be done.
the "ping" command returns exit status non-zero if it fails.
However, here even for machines that are down, it prints
"Machine is up"
The same command outside of the script has exit status 1 for the machine that is down.
What can be the issue?
Thanks