#!/bin/ksh ######################################################################### # WHO - Chris Grundemann # # WAT - push.ksh # # WEN - 02-APR-08 // Last Edit: 15-May-08 (CLG) # # WER - TWTC IP NOC # # WHY - This script will push configs out to Juniper routers using # # - pre-written or generated set commands # ######################################################################### ## # ## Copyright 2008 Chris Grundemann, All rights reserved. # ## # ## This software may be freely copied, modified and redistributed # ## without fee for non-commerical purposes provided that this license # ## remains intact and unmodified with any distribution. # ## # ## There is no warranty or other guarantee of fitness of this software. # ## It is provided solely "as is". The author(s) disclaim(s) all # ## responsibility and liability with respect to this software's usage # ## or its effect upon hardware, computer systems, other software, or # ## anything else. # ######################################################################### #-----------Variables--------------# #** enter the correct paths here **# PASTE=/paste_input.pl #past_input.pl can be found at http://www.chrisgrundemann.com/files/scripts/perl/ JLOGIN=/jlogin #jlogin is an expect script that comes with RANCID (http://www.shrubbery.net/rancid/) #----------------------------------# help () { print ' Chris wrote this script for personal use. If it messes something up, that is your fault for using it in the first place. By using this script you agree to this. Usage: push.sh -f push.sh -d push.sh -p [you then paste the list of routers and list of commands into the cli] ' } rundir() { # This section is utilized when the commands must be individualized for # each router. Generate your commands and save them in files that # are named with the hostname (or IP) of the router in question. for rtr in `ls -1 $RTRDIR` do cat $RTRDIR/$rtr >> temp.cmd $JLOGIN -x temp.cmd $rtr done } runfile() { # This section is utilized when the commands are the same for a # group of routers. Save your commands in one file and a list # of hostnames or IPs to act on in another. rm -f temp.cmd for rtr in `cat $RTRLST` do cat $CMD >> temp.cmd $JLOGIN -x temp.cmd $rtr done rm -f temp.cmd } runpaste() { # This section is utilized when the commands are the same for a # group of routers. With this option there is no need to create any # files ahead of time though, you can simply paste the two lists # onto the command line. You must have paste_input.pl for this to # work. rm -f paste.cmd rm -f paste.rtr print ' Paste the list of routers to act on:' $PASTE paste.rtr print ' Paste the commands to execute on all routers above:' $PASTE paste.cmd for rtr in `cat paste.rtr` do cat paste.cmd >> temp.cmd $JLOGIN -x temp.cmd $rtr done rm -f paste.cmd rm -f paste.rtr } while [ "$1" ]; do # Here we find out how the user wants to use this tool and # collect the needed variables. case "$1" in -d) RTRDIR=$2 rundir exit 0 ;; -f) RTRLST=$2 CMD=$3 runfile exit 0 ;; -p) runpaste exit 0 ;; *) help exit 0 ;; esac shift done ####### # END # #######