This is continuation post of the usage of Python Paramiko network device configuration script (netscript.py) I am currently testing. Let us say you have around 100 network devices accessible via SSH and you need to update their configuration. For example you need to add a new syslog server and remove the current one. In Cisco IOS, you would need to run these set of commands:
# Enter Configuration mode
configure terminal
# remove old syslog server
no logging 192.168.1.11
# add new syslog server
logging 192.168.1.10
end
# save current configuration
write memory
Imagine if you would need to connect to each network device using the same credentials with administrative privilige and run this set of commands again and again. This is very manual and monotonous.
I have made this easier using this simple Python script. All we need is to loop this script for every network device executing the same set of commands. Below is a simple bash script (mass_netscript.sh) to achieve this task.
I have made this easier using this simple Python script. All we need is to loop this script for every network device executing the same set of commands. Below is a simple bash script (mass_netscript.sh) to achieve this task.
#!/bin/bash
netscript="./netscript.py"
username="username_with_admin_privilege"
passwd="password"
verbose="-v"
if [ -z "$1" ]
then
echo "No target file supplied"
exit
fi
targetfile=$1
if [ -z "$2" ]
then
echo "No command file supplied"
exit
fi
command=$2
for target in $( cat $targetfile ); do
$netscript -t $target -u $username -p $passwd -c $commandfile $verbose
done
The target fille should contain the list of device IP address or hostname/FQDN (should be resolvable) one line per device.
host1_ip_adress
host2_ip_adress
host3_ip_adress
The command file should have the set of commands to be execute on each network device. Note the static variables in the script for the username and password as well as the verbose mode is you want terminal screen output for debugging purposes.
Common sense dictates that this bash script should be executed to the same group of network device where the command file is applicable. So all Cisco IOS device should be executed together with this script.
Hope this helps.
Common sense dictates that this bash script should be executed to the same group of network device where the command file is applicable. So all Cisco IOS device should be executed together with this script.
Hope this helps.