I've made an expect/bash script to retrieve cisco devices configuration; it's simple copy cisco running-configuration and save it using tftp.
#!/bin/bash
while read line;
do
device=$line;
expect << EOF
spawn telnet $device
expect "Username:"
send "username\n"
expect "Password:"
send "password\n"
send "copy running-config tftp://192.168.244.14\r"
expect "Address or name of remote host"
send "\r"
expect "Destination filename "
send "\r"
expect "secs"
send "exit\r"
close
EOF
done < /home/marco/Scrivania/Host.txt
exit 0
My issue is that I've several devices, some configured to accept telnet connections, other to accept only ssh connections. So, in my script,I would add something such as:
try to connect to device using telnet if isn't no response after 3 minutes, cancel 'spawn telnet...' command and try connect using ssh.
In witch way can I implement this?