我刚刚编写了一个脚本来自动将我们的 Cisco 设备备份到指定文件夹。/home/myusername/备份
我想要完成的是让脚本每周运行一次,将输出转储到 Backups 文件夹中,而不是覆盖它们,而是将旧配置存储在单独的目录中。如果可能,我们希望保留 1 个月的备份。当脚本运行并写入新输出时,前一个副本将沿文件树向下移动。文件树看起来像这样:
/Backups(newest backup)
--1_Week_Old
--2_Weeks_Old
--3_Weeks_Old
--4_Weeks_Old
这是我编写的现有脚本的示例。它运作良好,但我知道可以通过一些获得的经验来缩短它。我是脚本新手,所以轻松一点....
#!/usr/bin/expect
set timeout 20
# These are all the IP's:
set ip1 "X.X.X.X"
#These are all the hostnames:
set hostname1 "ASA_Firewall"
#These are the usernames
set username "RickyBobby"
# These are all the passwords:
set password "xxxxxxx"
set enableasa "xxxxxxxxx"
#This is the ASA Firewall - Point TFTP Directory to C:\cygwin\home\RickyBobby\Backups
spawn ssh $ip1
expect "password:"
send "$password\r"
expect ">" {
send "en\n"
expect "Password:"
send "$enableasa\r"
}
expect "#"
send "copy run tftp://X.X.X.X/Backups/$hostname1-confg\r"
expect "Source filename?"
send "\r"
expect "Address or name of remote host?"
send "X.X.X.X\r"
expect "Destination filename?"
send "\r"
expect "#"
send "exit\r"
我仍在学习过程中,所以任何帮助将不胜感激。谢谢!