This article provides script which will ping multiple IP addresses / Hostnames and report if they are UP or down.
Below is the script content.
When the script is executed it redirects the output to /tmp/result.out file as follows. As you can see it prints date and whether the hosts are up or down.
Below is the script content.
#!/bin/bash
# Program name: ping_multiple_ip_hosts.sh
echo
"`date`" >>/tmp/result.out
cat /tmp/hosts
| while read output
do
ping -c 1 "$output" >
/dev/null
if [ $? -eq 0 ]; then
echo "node $output is up"
>>/tmp/result.out
else
echo "node $output is down"
>>/tmp/result.out
fi
done
This script reads
the IP addresses / hostnames from /tmp/hosts file. The IP addresses have to be light this in /tmp/hosts file with 1 IP or hostname per line.
10.10.10.10
10.10.10.20
When the script is executed it redirects the output to /tmp/result.out file as follows. As you can see it prints date and whether the hosts are up or down.
Fri Aug 23 02:02:01
UTC 2019
node 10.10.10.10 is up
node 10.10.10.20 is up
Fri Aug 23 02:03:01
UTC 2019
node 10.10.10.10 is up
node 10.10.10.20 is up
Fri Aug 23 02:04:01
UTC 2019
node 10.10.10.10 is up
node 10.10.10.20 is up
Products to which Article Applies
All UNIX environments
No comments:
Post a Comment