telnet to multiple Hosts/Routers from linux/unix bash command line
#!/bin/bash
export USERNAME=xxxxx <user-name-to-connect-to-the-node>
export PDW=xxxxxxxx <password-of-the-user>
cat hosts.txt | while read H
#if the username and password are different for different nodes, the try here to get
# username and password in some variable. Awk/Perl or simple bash string replacement of variable
# H will do that.
do
( echo open $H
sleep 1
echo $USERNAME
sleep 1
echo $PDW
sleep 1
/somedir/some_script.sh 2>&1 > /dev/null
echo exit ) | telnet
done
Ref: http://www.unix.com/shell-programming-scripting/27474-perl-script-telnet.html

Leave a Reply