文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>自动登录cisco网络设备备份配置

自动登录cisco网络设备备份配置

时间:2010-08-05  来源:sorghum_cu

要求:
定时备份cisco网络设备配置,保存到某个目录下面

cisco路由器ip:192.168.64.4
执行脚本的linux:192.168.64.2
tftp server:192.168.64.1

1.这里是保存cisco路由器running-config到tftp服务器上

root@myubuntu:/home/myadmin# cat r7.sh
#!/usr/bin/expect -f
#auto telnet login
set timeout 30
set sshhost [lindex $argv 0]
#定义位置变量
set today [exec date +%Y%m%d]
#定义变量,把date执行的结果赋值给变量today,就能以日期为文件名了
spawn telnet $sshhost
expect "Password:"
send "cisco\r"
expect "*>"
send "enable\r"
expect "Password:"
send "cisco\r"
expect "*#"
send "copy running-config tftp:\r"
expect "*]?"
send "192.168.64.1\r"
expect "*]?"
send "$today\r"
interact

如果想保存扩展名的话,则命令如下
send "${today}.log\r"

2.每隔1小时备份一次
这里使用crontab软件

root@myubuntu:/home/myadmin# cat /var/spool/cron/crontabs/root
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (root installed on Wed Aug  4 01:01:48 2010)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (root installed on Wed Aug  4 00:58:18 2010)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
6 * * * * /home/myadmin/r7.sh 192.168.64.4


/var/spool/cron/crontabs/root
如果是root用户,就是root的文件
上面的文件的意思是每小时的第6分钟进行备份一次

启动crontab服务,守护进程为cron:
/etc/init.d/cron start

执行crontab命令:
crontab -u root /var/spool/cron/crontabs/root

 

 

相关阅读 更多 +
排行榜 更多 +
掌上皇御

掌上皇御

金融理财 下载
天翼校园

天翼校园

系统软件 下载
源新闻

源新闻

浏览阅读 下载