Here I have used Python Paramiko as my preferred approach. There have been several articles discussing how to use Paramiko but I am more focused in using it for network scripting. After reading these articles, I have managed to create a working script and uploaded in my github repository (netscript). Kindly note that this a work in progress.
To get this script working, you need to install Python and Paramiko on Linux (preferred). Check with your preferred Linux distribution in installing these. In my environment which is Debian Linux, these are installed with apt-get.
# ./netscript.py --help
netscript.py -t <target> -u <username> -p <password> -c <command_file> -v
apt-get install python python-paramiko
- target - IP address (preferred) or hostname (FDQN)
- username/password - network device access credentials (Note: account should have admin privilege)
- command_file - text file containing list of commands to execute.
# cat cisco_version.txt
terminal length 0
show version
# ./netscript.py -t 10.64.0.89 -u netscript -p xxxxxx -c cisco_version.txt -v
-----------------------
Input parameters
Target host : 10.64.0.89
Username : netscript
Password : xxxxxx
Command file : cisco_version.txt
Verbose : True
-----------------------
SSH connection established to 10.64.0.89
CISCO-TEST-SW-3750#terminal length 0
CISCO-TEST-SW-3750#
show version
Cisco IOS Software, C3750 Software (C3750-IPSERVICESK9-M), Version 12.2(55)SE6, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2012 by Cisco Systems, Inc.
Compiled Mon 23-Jul-12 13:22 by prod_rel_team
Image text-base: 0x01000000, data-base: 0x02F00000
ROM: Bootstrap program is C3750 boot loader
BOOTLDR: C3750 Boot Loader (C3750-HBOOT-M) Version 12.2(44)SE5, RELEASE SOFTWARE (fc1)
CISCO-TEST-SW-3750 uptime is 25 weeks, 2 days, 17 hours, 3 minutes
System returned to ROM by power-on
System restarted at 18:41:24 UAE Sat Oct 25 2014
System image file is "flash:/c3750-ipservicesk9-mz.122-55.SE6.bin"
This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
Closing SSH connection
# cat comware_version.txt
screen-length disable
display version
# ./netscript.py -t 10.64.0.88 -u netscript -p xxxxxx -c comware_version.txt -v
-----------------------
Input parameters
Target host : 10.64.0.88
Username : netscript
Password : xxxxxx
Command file : comware_version.txt
Verbose : True
-----------------------
SSH connection established to 10.64.0.88
<HP-TEST-SW-5120>screen-length disable
% Screen-length configuration is disabled for current user.
<HP-TEST-SW-5120>
display version
HP Comware Platform Software
Comware Software, Version 5.20, Release 1513P86
Copyright (c) 2010-2014 Hewlett-Packard Development Company, L.P.
HP A5120-24G SI Switch uptime is 25 weeks, 2 days, 17 hours, 14 minutes
HP A5120-24G SI Switch
128M bytes DRAM
128M bytes Nand Flash Memory
Config Register points to Nand Flash
Hardware Version is REV.B
CPLD Version is 002
Bootrom Version is 169
[SubSlot 0] 24GE+4SFP Hardware Version is REV.B
<HP-TEST-SW-5120>
Closing SSH connection