我的代码:
spawn telnet $ip
expect "Password: "
exp_send "$paswd\r"
expect "Router>"
exp_send "en\r"
expect "Password: "
exp_send "$paswd\r"
expect "Router#"
exp_send "\r"
expect "Router#"
exp_send "\r"
expect "Router#"
exp_send "\r"
expect "Router#"
exp_send "\r"
expect "Router#"
exp_send "conf t\r"
expect "Router(config)#"
exp_send "\r"
expect "Router(config)#"
exp_send "ip ftp username name\r"
expect "Router(config)#"
exp_send "ip ftp password name123\r"
expect "Router(config)#"
exp_send "end"
expect "Router#"
exp_send "\r"
expect "Router#"
exp_send "\r"
expect "Router#"
exp_send "\r"
expect "Router#"
exp_send "copy ftp: filename\r"
expect "Address or name of remote host []? "
exp_send "$remote_ip\r"
expect "Source filename []? "
exp_send "router-config1\r"
expect "Destination filename []? "
exp_send "/new/location\r"
expect "Router#"
输出:
Router(config)#ip ftp username name
Router(config)#ip ftp password name123
Router(config)#endTcpping succeeded for port 443.
Tcpping succeeded for port 443.
Router#
Router#
Router#copy ftp: filename
Address or name of remote host []? Tcpping succeeded for port 443.
Tcpping succeeded for port 443.
$remote_ip
Source filename []? Tcpping succeeded for port 443.
Tcpping succeeded for port 443.
filename
Destination filename [filename]? Tcpping succeeded for port 443.
Tcpping succeeded for port 443.
/new/location
%Warning:There is a file already existing with this name
Do you want to over write? [confirm]Tcpping succeeded for port 443.
Tcpping succeeded for port 443.
Accessing ftp://$remote_ip//filename...
%Error opening ftp://$remote_ip//router-config (No such file or directory)
Router#copy t1_working startup-config
Destination filename [startup-config]? Tcpping succeeded for port 443.
有人可以告诉我如何捕捉 NO SUCH FILENAME 的异常吗?