Blog |Follow Nick on Twitter| About
 

This is my first python project; the goal was simple replace manual labour with ones and zeros... in this case write a tool which can run multiple commands on multiple switches/routers.

I've called the tool Cisco Remote Automation via SSH, or C.R.A.SSH for short. The name is in homage to S.H.I.E.L.D because I really wanted the name to sound like "crash" as a way of reminding users that if you are not careful this script is a car-crash-waiting-to-happen!

The script on github: https://github.com/linickx/crassh. To use it, you'll need python with paramiko installed.

Usage can be simple, ./crassh.py (not forgetting to chmod 755 first!) and this prompt you to execute one command on a switch.

nick@linickx:~$ ./crassh.py -p
Enter the switch to connect to: 192.168.1.72
The switch command you want to run: show ver
Enter your username: nb
Enter your password:
Connecting to 192.168.1.72 ... 
192.168.1.72: Running show ver
show ver
Cisco IOS Software, C2960S Software (C2960S-UNIVERSALK9-M), Version 12.2(55)SE7, RELEASE SOFTWARE (fc1)

<CUT by Nick for breivity>

Configuration register is 0xF

SW01#
Switch 192.168.1.72 done


 ********************************** 
   Output files:
     - SW01-140808-010101.txt
 Script FINISHED ! 
 ********************************** 
nick@linickx:~$

The real power of the script is with the -s and -c options which allow you to work on multiple switches running multiple commands respectively.

A simple example is to automate configuring an interface description... create a text file called testconfig.txt with the following contents

show run int g1/9
conf t
interface GigabitEthernet1/9
description *** UNUSED ***
exit
exit
show run int g1/9

Then, run the command with the -c option (the -p option prints the file instead of writing to a file). e.g.

./crassh.py -c testconfig.txt -p

Here is the output.

[nick@linickx temp]$ ./crassh.py -c testconfig.txt -p
Enter the switch to connect to: Switch
Enter your username: nb
Enter your password:
Connecting to Switch ... 
Switch: Running show run int g1/9
show run int g1/9
Building configuration...

Current configuration : 174 bytes
!
interface GigabitEthernet1/9
 description ***** UNUSED *****
 switchport
 switchport access vlan 999
 no logging event link-status
 shutdown
 spanning-tree guard root
end

Switch#
Switch: Running conf t
conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#
Switch: Running interface GigabitEthernet1/9
interface GigabitEthernet1/9
Switch(config-if)#
Switch: Running description *** UNUSED ***
description *** UNUSED ***
Switch(config-if)#
Switch: Running exit
exit
Switch(config)#
Switch: Running exit
exit
Switch#
Switch: Running show run int g1/9
show run int g1/9
Building configuration...

Current configuration : 170 bytes
!
interface GigabitEthernet1/9
 description *** UNUSED ***
 switchport
 switchport access vlan 999
 no logging event link-status
 shutdown
 spanning-tree guard root
end

Switch#
Switch Switch done


 ********************************** 
 Script FINISHED ! 
 ********************************** 
[nick@linickx temp]$

Now, if you create a text file with a list of switches in it, called myswitches.txt like:

192.168.1.72
coreswitch.domain.local
accessswitch1.domain.local

And run:

./crassh.py -c testconfig.txt -s myswitches.txt -p

The you'll configure the description of G1/9 the same on all three switches!

I think now you're probably getting the idea, crassh can be used to deploy a standard config to switches, or run the same show command to gather information, show authentication sessions | inc VOICE to find dot1x authenticated ip-phones anyone?

 

 
Nick Bettison ©