Automated Remote VTY Command Script

From DocWiki

(Difference between revisions)
Jump to: navigation, search
(IP List in a File)
(added categories)
Line 1: Line 1:
[[Category:Technologies]]
[[Category:Technologies]]
[[Category:Network Management]]
[[Category:Network Management]]
 +
[[Category:Network Management and Automation]]

Revision as of 20:45, 1 June 2011


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

Rating: 5.0/5 (8 votes cast)

Personal tools