Automated Remote VTY Command Script
From DocWiki
(Difference between revisions)
(→Range of IPs) |
|||
| (3 intermediate revisions not shown) | |||
| Line 1: | Line 1: | ||
| - | |||
[[Category:Network Management]] | [[Category:Network Management]] | ||
| + | [[Category:Network Management and Automation]] | ||
| Line 77: | Line 77: | ||
# | # | ||
# Syntax: | # Syntax: | ||
| - | # [network@network bin]$ ./ciscoFile.sh | + | # [network@network bin]$ ./ciscoFile.sh MY_IPLIST_FILE.TXT |
# | # | ||
# HISTORY: | # HISTORY: | ||
| Line 86: | Line 86: | ||
rpass="mypass" | rpass="mypass" | ||
renable="myenable" | renable="myenable" | ||
| - | cmdList= | + | cmdList="commandlist.txt" |
while read line | while read line | ||
Latest revision as of 17:09, 22 February 2012
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 begin ip, the second one is the last octet of the 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 MY_IPLIST_FILE.TXT # # HISTORY: # Sergio Zavala 02/04/11 First Version ########################################################################## ruser="myuser" rpass="mypass" renable="myenable" cmdList="commandlist.txt" 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