Using Putty to Automate Cisco Devices

Sometimes you want to automate some cumbersome tasks in your Cisco devices, namely I am dealing with an old 3750 core router with OS version 12.x and I don’t want to login to it manually every time I want to change a config or shutdown an interface. Hence I thought I can make use of SSH command to access the device and automate it. But SSH doesn’t help at all due to exec channel issue of Cisco, in fact you can’t send multiple lines of command to your device via SSH command.

After searching a while I figured out that I can use Plink instead of SSH. the Plink belongs to PuTTY project and you can download it from here for windows users, or if you are linux user you can install it via command line.

using Plink, it is easy to communicate with your Cisco devices, One way that I automate some of my tasks is like following :

#!/bin/sh

plink -hostkey a7:98:f8:db:87:0d:fc:ec:4e:00:00:00:00:a8:fe:a8 -ssh -l USERNAME 1.1.1.1 -pw PASSWORD< /home/automate_change_vlan_101_103/commands101.txt

As you can see I defined a commands101.txt, inside this file I put my Cisco commands.

conf t
interface gi1/0/22
 no shutdown
do wr
exit
exit
exit

Breakdown :

The only thing you need to know is, you need to have the public key of your device. The -hostkey is attaching public key to Plink, so Plink works in silent mode and it won’t prompt you to add public key.

Happy Automating!

Leave a Reply

Your email address will not be published. Required fields are marked *