Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
1 reply Latest Post - ‏2004-12-14T17:16:32Z by SystemAdmin
SystemAdmin
SystemAdmin
232 Posts
ACCEPTED ANSWER

Pinned topic Cisco/Expect Help

‏2004-05-14T16:20:09Z |
I'm trying to automate the process of copying a configuration from a remote router to a TFTP server. I have the following script. The router logs show that I log in, but nothing happens tftp-wise. Any help would be greatly appreciated!

#!/usr/bin/expect -f
#
#
#
#
  1. usage: upload-config hostname username password configfilename
#
#
#
if { llength $argv < 5} {
puts "usage: upload hostname username password tftpip confgfilename"
exit 1
}
set router lindex $argv 0
set username lindex $argv 1
set password lindex $argv 2
set tftpip lindex $argv 3
set confgfilename lindex $argv 4
set timeout 20

log_user 0
spawn telnet $router

expect {
"Username:" {send $username\r}
}

expect {
"Password:" {send $password\r}
}

expect {
"#" {send "copy tftp run\n"}
}

expect {
"Address" {send $tftpip\r}
}

expect {
"Source" {send $confgfilename\r}
}

expect {
"Destination" {send "run\r"}
}

sleep 15

exit 0
Updated on 2004-12-14T17:16:32Z at 2004-12-14T17:16:32Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    232 Posts
    ACCEPTED ANSWER

    Re: Cisco/Expect Help

    ‏2004-12-14T17:16:32Z  in response to SystemAdmin
    Not sure how to do it in expect but using the net::telnet::cisco module
    use strict;
    use Net::Telnet::Cisco;
    print("What host would you like to backup to tftp?\n");
    my $host = <STDIN>;
    chomp($host);
    my $backup_host ="host_ip_here";
    my $session = Net::Telnet::Cisco->new(Host=>$host);
    $session->login('login','password_here');
    #Execute show interfaces
    my @output = $session->cmd('show ip route');
    #print @output;
    1. Enable mode
    if ($session->enable("enable_here") ) {
    @output = $session->cmd("copy system:/running-config "
    . "tftp://$backup_host/\n\n\n");
    } else {
    warn "Cant enable: " . $session->errmsg;
    }
    $session->close;