Pinging Many IP addresses and logging results
by Mary777 from LinuxQuestions.org on (#4YYYV)
Hello,
I am trying to ping many IP addresses existing in a text file called "iplist.txt", from a remote server (using telnet to connect to the server), and I want to put the results of the pings in a text file in an organized way that shows the date, time and ping outputs for each IP address.
I am getting an error:
can't read "(cat iplist.txt)": no such variable
while executing
"for addr in $(cat iplist.txt)"
Please any help for getting my final results? and How can I make many a schedule for this script and save each execution outputs in a file without overwriting the old one?
THANK YOU.
Code
#!/usr/bin/expect
# ssh to remote server
spawn telnet XXXX
expect "Username:"
send "XXXX\r"
expect "assword:"
send "XXXX\r"
# Test server connectivity using ping
for addr in $(cat iplist.txt)
do
echo "Pinging IP address "$addr
ping -c 3 "$addr" | while read pong; do echo "$(date): $pong"; done >> capture.txt
done


I am trying to ping many IP addresses existing in a text file called "iplist.txt", from a remote server (using telnet to connect to the server), and I want to put the results of the pings in a text file in an organized way that shows the date, time and ping outputs for each IP address.
I am getting an error:
can't read "(cat iplist.txt)": no such variable
while executing
"for addr in $(cat iplist.txt)"
Please any help for getting my final results? and How can I make many a schedule for this script and save each execution outputs in a file without overwriting the old one?
THANK YOU.
Code
#!/usr/bin/expect
# ssh to remote server
spawn telnet XXXX
expect "Username:"
send "XXXX\r"
expect "assword:"
send "XXXX\r"
# Test server connectivity using ping
for addr in $(cat iplist.txt)
do
echo "Pinging IP address "$addr
ping -c 3 "$addr" | while read pong; do echo "$(date): $pong"; done >> capture.txt
done