Wireless Access

last person joined: 19 hours ago 

Access network design for branch, remote, outdoor, and campus locations with HPE Aruba Networking access points and mobility controllers.
Expand all | Collapse all

Sharing "Expect" script to backup controllers

This thread has been viewed 12 times
  • 1.  Sharing "Expect" script to backup controllers

    Posted Jul 11, 2013 07:19 PM

    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



  • 2.  RE: Sharing "Expect" script to backup controllers

    EMPLOYEE
    Posted Jul 12, 2013 03:44 AM

    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.



  • 3.  RE: Sharing "Expect" script to backup controllers

    Posted Jul 12, 2013 09:27 AM

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



  • 4.  RE: Sharing "Expect" script to backup controllers

    EMPLOYEE
    Posted Jul 12, 2013 09:47 AM

    The command is

     

    backup flash

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



  • 5.  RE: Sharing "Expect" script to backup controllers

    Posted Jul 13, 2013 10:31 PM

    Thank you.



  • 6.  RE: Sharing "Expect" script to backup controllers

    Posted Aug 13, 2013 10:17 AM

    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"}
    }