1
我做了expect/bash脚本来检索思科设备配置;它很简单复制cisco running-configuration并使用tftp保存它。如何在产生ssh或telnet连接时处理超时?
#!/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
我的问题是,我已经几个设备,一些配置为接受telnet连接,另一只接受SSH连接。因此,在我的脚本中,我会添加如下内容:
尝试使用telnet连接到设备 如果在3分钟后没有响应,请取消'spawn telnet ...'命令并尝试使用ssh进行连接。
在巫婆的方式我可以执行此?