Wireless Access

Reply
Occasional Contributor II
Posts: 13
Registered: ‎09-15-2011

Sharing "Expect" script to backup controllers

Here is a script that I have been working on to automate backup and figured I would share.  Went through a lot of trial and error with trying to do this in Python and found it is just easier to do with Tcl\Expect.  Maybe it will help someone or give someone some ideas on how to improve it to make it work better for them.  I run this in a cron job.  name the script whatever you like and add execute permissions and it should work.  Please share ideas imporvements etc...

 

 

#!/usr/bin/expect
#CF Aruba backup running confug 7-11-13

# Spawn ssh

spawn ssh admin@your_host
sleep 2

#Catch the password prompt and send supplied password
expect {
"word:" {send "yourpass\r"}
}
sleep 1

#Get into enable mode and issue the command to backup configuration
expect {
"*>" {send "en\r"}
}
sleep 1
expect {
"*word:" {send "enablepass\r"}
}
sleep 1
expect {
"#" {send "copy running-config tftp: ip.of.tftp runn-conf-control1.txt \r"}
}
sleep 10
# Exit cleanly
expect {
"*#" {send "exit\r"}
}
sleep 1
expect {
"*>" {send "exit\r"}

}

sleep 1

Aruba
Posts: 1,296
Registered: ‎08-29-2007

Re: Sharing "Expect" script to backup controllers

Excellent tips.   We use pretty much the same thing as well.

 

You might want to consider getting the flashbackup instead as this is far more useful in replacing a unit.  The config file is contained within that anyway.


If my post is helpful please give kudos, or mark as solved if it answers your post.

ACCP, ACMP, ACMX #294
mclarke@arubanetworks.com
Occasional Contributor II
Posts: 13
Registered: ‎09-15-2011

Re: Sharing "Expect" script to backup controllers

Thanks for the reply.  Do you have any specific links to information on the "Flashbackup"?  Thanks in advance.

Aruba
Posts: 1,296
Registered: ‎08-29-2007

Re: Sharing "Expect" script to backup controllers

The command is

 

backup flash

 the file will be called flashbackup.tar.gz, so you can adjust your script to suit.


If my post is helpful please give kudos, or mark as solved if it answers your post.

ACCP, ACMP, ACMX #294
mclarke@arubanetworks.com
Occasional Contributor II
Posts: 13
Registered: ‎09-15-2011

Re: Sharing "Expect" script to backup controllers

Thank you.

Occasional Contributor II
Posts: 13
Registered: ‎09-15-2011

Re: Sharing "Expect" script to backup controllers

[ Edited ]

Updating thread to include new script that backs up entire flash to tftp.  Maybe someone will find it useful. Please note that this script already assumes you have logged into the controller via ssh from the box you intend run the script from due to the ssh fingerprint.   

 

#!/usr/bin/expect
#Start SSH session
spawn ssh admin@your_controller
sleep 2

#password prompt and send password
expect {
"word:" {send "password\r"}
}
sleep 1

#Login to enabled mode and issue the command to backup flash
expect {
"*>" {send "en\r"}
}
sleep 1
expect {
"*word:" {send "password\r"}
}
sleep 1
#Backup flash
expect {
"#" {send "backup flash\r"}
}
sleep 120
#Send flash.tar to tftp
expect {
"#" {send "copy flash: flashbackup.tar.gz tftp: tftp_ip file-name.tar.gz\r"}
}
sleep 15
#Delete backup from controller
expect {
"#" {send "delete filename flashbackup.tar.gz\r"}
}
sleep 1
#Exit cleanly
expect {
"*#" {send "exit\r"}
}
sleep 1
expect {
"*>" {send "exit\r"}
}

Search Airheads
Showing results for 
Search instead for 
Did you mean: