one script for multiple routers

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered
I am interested in a script that uses only a mac address in the format XX:XX:XX:XX:XX:XX OR XXXX.XXXX.XXXX to execute 5 static commands across multiple routers.

Essentially i want to be able to copy/paste a mac address for a program such as SecureCrt/Putty. After i paste the mac address i would like the following commands to execute on after the other

1. sh cab mod 'COPIED MAC ADDRESS'
2. sh cab mod 'COPIED MAC ADDRESS' conn
3. sh cab mod 'COPIED MAC ADDRESS' flap
4. sh cab mod 'COPIED MAC ADDRESS' cpe
5. sh ip arp 

Is this possible. below is what is was able to come up with so far using script recorder in Secure Crt, upon that i don't know what else to do.  

Problem 1 
I would have to know what router the mac address is on to run the script. (i would like script to run all routers i have connected at one time) Note: if i have to do each router at a time that is ok if aforementioned is not possible and/or scripting to complex

Problem 2

Because mac address' are different and i have to manually input them i would mean that commands 2-5 would not execute if using script below.

I am sure that there is a way the edit script where after MAC ADDRESS is copied into command_1 , that same MAC ADDRESS will be place into subsequent commands 2-4. But i just don't know the programming language.

Can some please assist per below

#$language = "VBScript"#$interface = "1.0"

crt.Screen.Synchronous = True

' This automatically generated script may need to be
' edited in order to work correctly.

Sub Main
crt.Screen.Send "sh cab mod FF:FF:FF:FF:FF:FF" & chr(13)
crt.Screen.WaitForString "Switch>"
crt.Screen.Send "sh cab mod FF:FF:FF:FF:FF:FF conn" & chr(13)
crt.Screen.WaitForString "Switch>"
crt.Screen.Send "sh cab mod FF:FF:FF:FF:FF:FF flap" & chr(13)
crt.Screen.WaitForString "Switch>"
crt.Screen.Send "sh cab mod FF:FF:FF:FF:FF:FF cpe" & chr(13)
crt.Screen.WaitForString "Switch>"
crt.Screen.Send "sh ip arp " & chr(13)
End Sub
Photo of Michael Smalls

Michael Smalls

  • 142 Points 100 badge 2x thumb

Posted 3 years ago

  • 0
  • 1
Photo of Jeremy

Jeremy, Embassador

  • 9,788 Points 5k badge 2x thumb
If you can use perl, I will write you a simple perl script to do what you want.  I write scripts like these all the time.  You can also use Expect! to do some automation, although it does suck. 
Photo of Michael Smalls

Michael Smalls

  • 142 Points 100 badge 2x thumb
i don't know if SecureCrt/Putty can run perl scripts but i can try if i had a script
Photo of Michael Smalls

Michael Smalls

  • 142 Points 100 badge 2x thumb
ok i just quick checked and yes perl will work, i just will need the PerlScript engine
Photo of Michael Smalls

Michael Smalls

  • 142 Points 100 badge 2x thumb
ttt
Photo of Jeremy

Jeremy, Embassador

  • 9,788 Points 5k badge 2x thumb
When I get back from the gym, I will write you a script.  
Photo of Jeremy

Jeremy, Embassador

  • 9,788 Points 5k badge 2x thumb
I'm sorry.  I got pulled away on something and forgot.  Can you have access to a linux VM or something?  I feel like I could write this much better using expect or something vs using perl for windows.  Perl for windows is okay, but then you will have to install the perl ssh module and it just gets complicated.  
Photo of Jeremy

Jeremy, Embassador

  • 9,788 Points 5k badge 2x thumb
Actually, let me see if I can use cygwin.  If so, this simple program is quite awesome.

https://www.cygwin.com/
Photo of Michael Smalls

Michael Smalls

  • 142 Points 100 badge 2x thumb
If u do use Cygwin to write script...will the script b able to work in a terminal emulator like putty? ...or it would mean I need Cygwin to use script
(Edited)
Photo of Jeremy

Jeremy, Embassador

  • 9,788 Points 5k badge 2x thumb
Well, Cygwin is a terminal emulator.  So you can even replace Putty with it.  Because it's a linux command line :).  When I ssh to a switch, I do ssh -l myusername 10.0.0.1

The terminal asks me for my password and I type it in.  Boom, im ssh'ed into a switch.  You can also telnet into a switch just as easy.  If for ssh you don't want to use the -l switch, you can do ssh myusername@10.0.0.1.  Anyway, cygwin is very easy to use for what I am suggesting.  
Photo of Michael Smalls

Michael Smalls

  • 142 Points 100 badge 2x thumb
Sounds cool
(Edited)
Photo of Michael Smalls

Michael Smalls

  • 142 Points 100 badge 2x thumb
thanks much