Expect may be a good candidate to consider for the job.
Below is an example template I've put together that is commented out for you to play with. It will log into a WLC, grab the running configuration and append it to a file of your choice.
The example file name and location is /var/log/script-log/config-log.txt
You'll need to modify the file name and location to a file of your choice (with adequate permissions) as well as the username, password and IP address of your WLC.
Finally you can edit your crontab to execute the backup script using a desired interval.
Crontab example:
# Run configuration backup every night at midnight
0 0 * * * /path/to/script/script-name
Configuration backup script example:
#!/usr/bin/expect
set timeout 15
set user "username-here"
set password "password-here"
set ipaddress1 "ip-address-here"
# Store the current date in 'date' and add header to log for appending separation
catch { exec sh -c { date } } date
set env(date) "$date"
exec sh -c {
{
echo -e "\n\n==================================================="
echo -e "= WLC Configuration - $date"
echo -e "===================================================\n\n"
} >>/var/log/script-log/config-log.txt
}
# Log to the log.txt file and append to the log on subsequent runs (a)
set log [open "/var/log/script-log/config-log.txt" a]
set accum {}
# Expect diagnostic information with 1 | off = 0
exp_internal 0
# View stdout with 1 | off = 0
log_user 0
# Connect to physical WLC (ipaddr) with ssh
spawn ssh $ipaddress1
match_max 100000
sleep 1
match_max [expr 32 * 1024]
while 1 {
expect {
"no)?" {send "yes\r"}
"n as:*" {send "$user\r"}
"ser:*" {send "$user\r"}
"assword:*" {send "$password\r"}
"r) >" {break}
"denied" {send_user "Can't login\r"; exit 1}
"refused" {send_user "Connection refused\r"; exit 2}
"failed" {send_user "Host exists. Check ssh_hosts file\r"; exit 3}
timeout {send_user "Timeout problem\r"; exit 4}
}
}
# send carriage return (\r) to make sure we get back to CLI prompt
send "\r"
sleep 1
# Remove scroll limit and show running configuration
send "config paging disable\r"
sleep 1
send "show run-config\r"
sleep 1
expect {
"nue..." {send "\r"}
}
sleep 1
send "logout\r"
sleep 1
# Upon logging out you can either save any pending changes with y or simply use n to ignore them
send "y\r"
sleep 4
# Grab string that matched the greedy regexp
expect {
-regexp {..*} {
set accum "${accum}$expect_out(0,string)"
exp_continue
}
}
puts $log $accum