Automated Remote VTY Command Script
From DocWiki
Revision as of 04:41, 5 February 2011 by Sergio.zavala@sidetec.com.mx (Talk | contribs)
Contents |
Automated Remote VTY Script
Range of IPs
#!/bin/bash
#########################################################################
# ciscoRange.sh
#
# This is a shell that loops in a range of consecutive IPs with
# the expect command vty_runcmd.exp
#
# Adapted by Sergio Zavala (sergio.zavala at sidetec.com.mx), Feb/2011
#
# First arg is the ip, the second one is the last octet end ip
# Syntax:
# [network@network bin]$ ./ciscoRange.sh 192.168.2.1 10
#
# HISTORY:
# Sergio Zavala 02/04/11 First Version
##########################################################################
# highest valid IP octet value
MaxValue=255
ip=$1
endip=$2
ruser="myuser"
rpass="mypass"
renable="myenable"
cmdList="commandlist.txt"
baseaddr="$(echo $ip | cut -d. -f1-3)"
lsv="$(echo $ip | cut -d. -f4)"
while [ $endip -ge $lsv ]
do
if [ $lsv -eq $MaxValue ] ; then
echo "edge case not implemented"
exit 1
fi
echo ""
echo "::::::::::::::::::::::::::::::::"
echo $baseaddr.$lsv
echo "::::::::::::::::::::::::::::::::"
# Calling the expect script
./vty_runcmd.exp -h $baseaddr.$lsv -u $ruser -p $rpass -e $renable -f ./$cmdList > $baseaddr.$lsv.cfg
lsv=$(( $lsv + 1 ))
done
exit 0
IP List in a File
#!/bin/bash ######################################################################### # ciscoRange.sh # # This is a shell that loops inside a file with IPs, executing # the list and using the variables in the expect command vty_runcmd.exp # # Adapted by Sergio Zavala (sergio.zavala at sidetec.com.mx), Feb/2011 # # Syntax: # [network@network bin]$ ./ciscoFile.sh MYFILE.TXT # # HISTORY: # Sergio Zavala 02/04/11 First Version ########################################################################## ruser="myuser" rpass="mypass" renable="myenable" cmdList=$1 while read line do if [ $line != "" ]; then echo "" echo "::::::::::::::::::::::::::::::::" echo $line echo "::::::::::::::::::::::::::::::::" # Calling the expect script ./vty_runcmd.exp -h $line -u $ruser -p $rpass -e $renable -f ./$cmdList > $line.cfg fi done < $1 exit 0