Data una lista di IP si collega ad ogni switch in telnet e lancia il comando di backup in modo da salvare sul tftp server un file con IP.cfg
questo è il comando che viene lanciato è adatto agli switch Hp Procurve
copy startup-config tftp 10.0.82.22 10.0.64.133.cfg
copy startup-config tftp 10.0.82.22 10.0.64.134.cfg
#!/usr/bin/expect set iptftp "10.0.82.22" set ip "10.0.64.133" set login "administrator" set password "xxxxxxxxxx" set hostlist [open "/home/leonardo/Backup-TFTP-Switch/ip-switch.txt" "r"] set ip [read -nonewline $hostlist] foreach line [split $ip \n] { set cmd1 "copy startup-config tftp $iptftp $line.cfg" # send $cmd1\n togliere il commento ve vedere a video i comando che verrà lanciato spawn telnet ${line} expect "inue"; send "\r"; expect "Usename:"; send ${login}\r; expect "Password:"; send ${password}\r; expect "#" send ${cmd1}\r; expect "#" send "exit\r"; expect ">" send "exit\r" expect "?" send "y/r" }
questo il file che viene letto con la lista degli IP
leonardo@$ cat /home/leonardo/Backup-TFTP-Switch/ip-switch.txt
10.0.64.133
10.0.64.134