Automate SSH Login to CISCO Device and Capture show running-config to log file with Expect

Step 1: Install expect (Centos 6.7 32bit)
yum install expect

Step 2: Verify expect install correct
expect –v

Step 3: Create Working Folder for Script
cd $HOME
mkdir CiscoAutomation
cd CiscoAutomation

Step 4: Create expect script with vi
vi TestCISCOLogin.exp

=> Script file contents
#!/usr/bin/expect
set timeout 10
set hostname [lindex $argv 0]

set username "username"
set password "password"
set enablepassword "password"

spawn ssh $username@$hostname

expect "Password:" {
  send "$password\n"

  expect ">" {
    send "en\n"
    expect "Password:"
    send "$enablepassword\n"
expect "#"
send "terminal length 0\r"
expect "#"
send "show running-config\r"
log_file  /var/log/cisco-running-config-$hostname
expect "#"
send "exit\n"
  }
  interact

}

Comments

Popular posts from this blog

Basic Send Message to MQ with Java and IBM MQ JMS

Basic Receive Message to MQ with Java and IBM MQ JMS

Creating a simple Alert / Success Message with ASP.NET/VB using Bootstrap