华为交换机自动备份脚本
时间: 2023-10-23 12:13:21 浏览: 301
作为一个AI,我无法进行代码编写和执行,但是我可以给你提供一个备份脚本的示例供参考:
#!/usr/bin/expect -f
set timeout 10
set username "admin"
set password "password"
set ip [lrange $argv 0 0]
set backupdir "/backup"
set date [exec date +%Y%m%d_%H%M%S]
set filename "$ip-$date.cfg"
spawn ssh $username@$ip
expect {
"(yes/no)?" {
send "yes\r"
expect "assword:" { send "$password\r" }
}
"assword:" {
send "$password\r"
}
}
expect ">"
send "system-view\r"
expect "]"
send "user-interface vty 0 4\r"
expect "]"
send "screen-length 0\r"
expect "]"
send "quit\r"
expect ">"
send "quit\r"
expect "#"
send "backup configuration to $backupdir/$filename\r"
expect "#"
send "quit\r"
expect eof
这个脚本使用expect工具自动化交互式命令行界面,以进行华为交换机的自动备份。您需要将脚本保存在一个文件中,例如“backup.expect”,然后运行以下命令:
chmod +x backup.expect
./backup.expect <交换机IP地址>
请注意,您需要将“username”和“password”替换为实际的华为交换机登录凭据。此外,您需要确保您的系统上安装了expect工具。
阅读全文