0

I would like to run a daily script the cleans my switch arp. I enabled SSH on my switch. how do I connect to the switch using a simple shell script? I'm not sure how to provide the SSH password and the enable password. Thanks!! Dotan.

edotan
  • 1,786
  • 12
  • 37
  • 57
  • I'm guessing you'll have a bit of a hard time trying to do this entirely using a shell script. Look into expect, maybe python+pexpect+paramiko. – ptman May 07 '13 at 06:06
  • I'm concerned why you want to clean out the switch's ARP table. – Tom O'Connor May 07 '13 at 08:47

3 Answers3

4

You need to combine your bash script with expect( it is a scripting program written in Tcl that was built to automate tasks for other interactive programs, such as Cisco's IOS)

Something like this, it uses telent here, but will get you started:

#!/usr/bin/expect -f
#! /bin/bash
#set force_conservative 0 ;
# set to 1 to force conservative mode even if
# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg }
}
set timeout 3000
log_user 1
set var1 [lindex $argv 0 ]
set var2 [lindex $argv 1]
puts $var1
puts $var2
spawn telnet $var1
expect "Username: "
send -- "myciscouser\r"
expect "*assword: "
send -- "mypassword\r"
log_user 1
expect "*>"
send "en\r"
expect "*assword: "
send -- "myenablepassword\r"
expect "$var2"
send-- "show clock\r"
send -- "exit\r"

Hope this helps.

Danila Ladner
  • 5,241
  • 21
  • 30
4

For such simple action I'd suggest looking at kron, built-in scheduler to run commands in IOS: e.g. to clear arp each day at 7:44 enable

conf t

kron policy-list daily_arp cli clear arp

kron occurrence DAILY at 7:44 recurring policy-list daily_arp

Yuri
  • 108
  • 5
0

You can use "expect" tool to connect to cisco switch and execute some command.

"Expect is a program that "talks" to other interactive programs according to a script.Following the script, Expect knows what can be expected from a program and what the correct response should be. An interpreted language provides branching and high-level control structures to direct the dialogue. In addition, the user can take control and interact directly when desired, afterward returning control to the script."

More details here

cuonglm
  • 2,346
  • 2
  • 15
  • 20