yum -y install expect
switchBK.sh
chmod 775 switch.sh
建立 shell
#!/usr/bin/expect
## TomDV
## http://blog.penumbra.be/2010/02/expect-scripts-backup-cisco-config/
set timeout 600
# —————- configuration device —————- #
## device 1
set device1
set tftp
set device1_user
set device1_pass
# ————– run command ————– #
## device 1
spawn ssh -l $user $device
expect “Password:”
send “$passn”
expect “#”
send “copy running-config tftp://$tftpn”
expect “$tftp”
send “n”
expect “Destination”
send “n”
expect copied
send “exitn”