#!/usr/bin/expect -f ##################################################################### # # # This is a script for backing up Siemens Scalamce switches. # # The script logs in and connects with SSH to the switch, # # then copies the current configuration to a TFTP server. # # (The Scalance switches do not support a more secure protocol) # # # # Make sure that you have expect installed on your system. # # Add/change the address of the TFTP server in the script below. # # Supply the hostname or IP address of the switch together with # # a username and a password as arguments to the script. # # # # There is no confirmation from within a Scalance switch to see if # # the command "cfgsave" was successful. # # So this script is not able to tell if the configuration backup # # is actually on the TFTP server when finished. # # # # The script can be added to Op5 or some other Nagios like system, # # or automated in other ways. # # # # Written by farid.joubbi@consign.se # # # # Version history: # # 1.0 2015-08-17 Initial version. # # 0.9 2015-02-16 Proof of concept. # # # ##################################################################### # Change this variable to the address of your TFTP server. set TFTP_Server 192.168.0.1:69 set timeout 10 set IPaddress [lindex $argv 0] set Username [lindex $argv 1] set Password [lindex $argv 2] # Change log_user from 0 to 1 if you want to see what happens. log_user 0 if {[llength $argv] != 3} { send_user "Wrong amount of arguments!\nUsage: ./backup_scalance hostname/address username password\n" exit 3 } # you might have to change the path to SSH below. spawn /usr/bin/ssh -o "StrictHostKeyChecking no" $Username@$IPaddress expect { "invalid user" { send_user "\ninvalid user\n" exit 2 } timeout { send_user "\nSSH to $IPaddress timed out!\n" exit 2 } "assword: " } send "$Password\r" expect { "Permission denied, please try again." { send_user "\nWrong password\n" exit 2 } "CLI>" } # Finally logged in. send "SYSTEM\r" expect "\\SYSTEM>" # On X-300 the command is SAVELOAD, while on a X-200 it's LOADSAVE... send "SAVELOAD\r" expect { "Wrong command: SAVELOAD" { send "LOADSAVE\r" expect "\\LOADSAVE" } "\\SAVELOAD" } # From here on the prompt is either "CLI\SYSTEM\SAVELOAD>" or "CLI\SYSTEM\LOADSAVE>" depending on version. send "server $TFTP_Server\r" expect "\\SYSTEM" send "cfgname SCALANCE-$IPaddress\r" expect "\\SYSTEM" send "cfgsave\r" expect "\\SYSTEM" send_user "\nBacked up $IPaddress to $TFTP_Server/SCALANCE-$IPaddress\n" send "exit\r" exit 0