Friday, December 18, 2009

Script to backup Cisco Device Config

A handy expect script on Linux to backup your routers, switches, AP, or other IOS devices configuration.  Make sure you have “expect” installed on your Linux box.


set timeout 5
log_user 1

# Include your hosts in the hostlist
set hostlist "rt01 rt02 sw01 sw02"
foreach host $hostlist {
set prompt [append $host "#"]
spawn telnet $host
expect $prompt
send "term len 0\r"
expect $prompt
set time [exec date \+\%y\%m\%dT\%H\%MJ]
set filename [append host "-" $time]

# The config file storage location
log_file /home/pandaeatsbamboo/cfgbackup/$filename
send "show run\r"
expect $prompt
send "exit\r"

1 comment:

ZeroKoOoL said...

Thanks. I have a similar script that was developed by my team. I added RCS for revision control. In case script finds a configuration change from last file in RCS it sends a alert via email to admin. and will the changed configuration lines. It makes huge difference to keep an eye on unauthorized configuration changes.