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