#!/bin/sh set -x # # The check_cisco.sh script is command and control wrapper for an Expect # script, called config-engine.exp. These tools in combination perform a # check on a router for updates. Any changes are reported via syslog # or via SMTP mail. # # The script tool is designed to run from Cron on a host # running a TFTP server. As long as the TFTP server is local, the script(s) # can run as a command line tool. # # The script requires two command-line values and the # short . The ip address tells the expect script what address to # open a VTY session with. The hostname variable is used for naming the TFTP # server directory and the configuration backup filenames. The fully # qualified domain name can be used but will result in long TFTP directory # and file names. # # In addition to the cli variables, two script variables "TFTP="and the "TROOT=" need to be defined. # # The "TFTP=" variable should be the ip address of the TFTP server. In order # for the file comparison and reporting functions to work the rover/config- # eng tools should be run from the same host that is functioning as the TFTP # server. If these functions are not required, comment out the SYSLOG report # and Mail Report sections. # # command syntax rover # # User Defined Config Variables # TFTP Server Address TFTP=166.107.239.39 # TFTP Server root directory (as defined in inetd.conf) TROOT=/tftpboot # User or Users addresses that receive event reports via SMTP mail RTP="joe@tasvorite.com" # Under normal operating conditions, i.e., run from the host functioning as # the TFTP server. No changes are required beyond this point. # Test for command line variables: # Was a target address provided? if [ "$1" = "" ] then echo "Target IP address is required, run command with -h to see required var iables";exit elif [ "$1" = "-h" ] then echo "Config_rover.sh " exit fi # Was a hostname provided? if [ "$2" = "" ] then echo "Hostname is required" exit fi TFTPIP="$1" THOST="$2" # Create TFTP directory and placeholder file # Event Stamp Format TS=`date +%d` # TFTP Directory-Name format TFTPD="$THOST-$TFTPIP" # TFTP Filename TFTPF="$TFTPD/$TS.conf" # Setting TFTP Server Paramaters mkdir $TROOT/$TFTPD > /dev/null 2>&1 chmod 777 $TROOT/$TFTPD touch $TROOT/$TFTPF chmod 666 $TROOT/$TFTPF # Run Configuration-Engine # Define where the Configuration-Engine script resides CONFENG=$THOST.exp # Run Configuration-Engine script, the target address and other variables are # passed to configuration-engine as command line variables #expect -d $CONFENG $TFTPIP $TFTP $TFTPF > /dev/null 2>&1 expect -d $CONFENG $TFTPIP $TFTP $TFTPF cd $TROOT cmp -s $TROOT/$TFTPD/check.conf $TROOT/$TFTPF if [ "$?" = "1" ] then # Mail Report echo "`date` Cisco router changes on $THOST" > /tmp/tempfile.$$ diff $TROOT/$TFTPD/check.conf $TROOT/$TFTPF >> /tmp/tempfile.$$ mail -v $RTP -s "Change Report for $THOST" < /tmp/tempfile.$$ rm /tmp/tempfile.$$ fi # Create a backup of current saved configuration cp $TROOT/$TFTPF $TROOT/$TFTPD/check.conf > /dev/null 2>&1 # Now compare running with stored configuration cmp -s $TROOT/$TFTPD/check.conf $TROOT/$TFTPF.start if [ "$?" = "1" ] then # Mail Report echo "`date` Warning, start and running configurations dont match on $THOST" > /tmp/tempfile.$$ diff $TROOT/$TFTPD/check.conf $TROOT/$TFTPF.start >> /tmp/tempfile.$$ mail -v $RTP -s "Warning Report for $THOST" < /tmp/tempfile.$$ rm /tmp/tempfile.$$ fi