cisco设备自动备份脚本

来源:互联网 发布:淘宝直播正式上线运营 编辑:程序博客网 时间:2024/04/28 13:31

linux下交互式登录工具:expect

需要自己安装

yum install expect

安装完成即可,expect功能非常强大……

脚本代码如下

iplist.dat为设备IP文件

serverlist.dat为tftp备份服务器IP文件

这样添加设备或者更改tftp服务器IP的话只需要修改这2个文件即可,不需要修改脚本。

将该脚本放到计划任务中执行,将输出结果重定向到/dev/null。

#!/usr/bin/expect -f
set IPlist [exec cat /tmp/iplist.dat]
set Serverlist [exec cat /tmp/serverlist.dat]
foreach Ser $Serverlist {
        foreach IP $IPlist {
        spawn telnet $IP
        expect "Username:"
        send "username\n"
        expect  "Password:"
        send "******\n"
        expect  "#"
        send "copy running-config tftp:\n"
        expect "Address or name of remote host"
        send "$Ser\n"
        expect "Destination filename"
        send "\n"
        expect "#"
        send "exit\n"
        expect eof
        }
}

原创粉丝点击