#!/bin/sh # # Simple script checks to see if tac_plus is running and if it is not # it restarts it. The tool can be run from CRON or from the command line # # Global Variables TACPID="/etc/tac_plus.pid" # Tac_plus deamon location TAC="/usr/sbin/tac_plus" # Tac_plus default config TACCONF=/etc/tacacs.conf ################ List running tac_plus processes echo " " rm -rf /var/tmp/trun touch /var/tmp/trun echo "PID Service Config File Port" > /var/tmp/trun; ps -aux | grep $TAC | awk '{print $2"\t" $11, $13,$15}' >> /var/tmp/trun cat /var/tmp/trun | grep -v "grep" echo " " ################ Tac_Plus runnng on the standard service port report to the CLI ############# # Varibles if [ "$1" = "-s" ] then more /var/tmp/trun;exit fi #if [ "$1" = "" ] #then #$TACPID #fi # If no PID file exists if [ "$1" = "" ] then ls -A $TACPID 2>/dev/null | grep -c "$TACPID" > /var/tmp/cpid fi if [ "$1" = "" ] then if [ "`cat /var/tmp/cpid`" = "0" ] then $TAC -C $TACCONF -d 32 ;echo "No PID File, Starting tac_plus on port 49, PID `cat $TACPID`";exit fi fi # # If PID File Exists ps -aux | awk '{print $2}' | grep -c "`cat $TACPID`" > /var/tmp/testf if [ "$1" = "" ] then if [ "`cat /var/tmp/testf`" -gt "0" ]; then echo "tac_plus is up PID `cat $TACPID`";exit elif [ "`cat /var/tmp/testf`" = "0" ]; then echo "tac_plus is down";$TAC -C $TACCONF -d 32;echo Restarting tac_plus PID `cat $TACPID`;exit fi fi # Stopping the "default' tac_plus service if [ "$1" = "-k" ] then ps -aux | awk '{print $2}' | grep -c "`cat $TACPID`" > /var/tmp/pcheck fi if [ "$1" = "-k" ] then if [ "`cat /var/tmp/pcheck`" = "1" ] then kill -TERM `cat $TACPID`;echo "Shutting Down the tac_plus service PID `cat $TACPID`";exit else echo "The tac_plus process does not exist";exit fi fi # Reload the "default' tac_plus service if [ "$1" = "-r" ] then ps -aux | awk '{print $2}' | grep -c "`cat $TACPID`" > /var/tmp/pcheck fi if [ "$1" = "-r" ] then if [ "`cat /var/tmp/pcheck`" = "1" ] then kill -USR1 `cat $TACPID`;echo "Reloading the tac_plus service PID `cat $TACPID`";exit else echo "The tac_plus process does not exist";exit fi fi ################ Tac_Plus runnng on a non stardard service port report to the CLI ############# # Stopping the non-standard port tac_plus service if [ "$1" = "-kp" ] then TACPID="/etc/tac_plus.pid.$2" fi if [ "$1" = "-kp" ] then PORT="$2" fi if [ "$1" = "-kp" ] then if [ "$2" = "" ] then echo "The PID value is missing";exit fi fi if [ "$1" = "-kp" ] then if [ "`awk '{print $4}' /var/tmp/trun | grep -c $2`" = "0" ] then echo PID does not exist;exit fi fi if [ "$1" = "-kp" ] then ps -aux | awk '{print $2}' | grep -c "`cat $TACPID`" > /var/tmp/nspcheck fi if [ "$1" = "-kp" ] then if [ "`cat /var/tmp/nspcheck`" = "1" ] then kill -TERM `cat $TACPID`;echo "Shutting Down the tac_plus service PID `cat $TACPID`";exit else echo "The tac_plus process does not exist";exit fi fi # Reloading the non-standard port tac_plus service if [ "$1" = "-rp" ] then TACPID="/etc/tac_plus.pid.$2" fi if [ "$1" = "-rp" ] then PORT="$2" fi if [ "$1" = "-rp" ] then if [ "$2" = "" ] then echo "The PID value is missing";exit fi fi if [ "$1" = "-rp" ] then if [ "`awk '{print $4}' /var/tmp/trun | grep -c $2`" = "0" ] then echo PID does not exist;exit fi fi if [ "$1" = "-rp" ] then ps -aux | awk '{print $2}' | grep -c "`cat $TACPID`" > /var/tmp/nspcheck fi if [ "$1" = "-rp" ] then if [ "`cat /var/tmp/nspcheck`" = "1" ] then kill -TERM `cat $TACPID`;echo "Shutting Down the tac_plus service PID `cat $TACPID`";exit else echo "The tac_plus process does not exist";exit fi fi # Starting tac_plus on non-standard port if [ "$1" = "-p" ] then PORT="$2" fi if [ "$1" = "-c" ] then PORT="$2" fi if [ "$1" = "-p" ] then TACPID="/etc/tac_plus.pid.`echo $2`" fi if [ "$1" = "-c" ] then TACPID="/etc/tac_plus.pid.`echo $2`" fi if [ "$1" = "-p" ] then if [ "$2" = "" ] then echo "Missing Port Definition";exit fi fi if [ "$1" = "-c" ] then if [ "$2" = "" ] then echo "Missing Port Definition";exit fi fi if [ "$1" = "-c" ] then if [ "$3" = "" ] then echo "Missing configuration file";exit fi fi # Starting tac_plus on non-standatd port if no PID file exists with the default config file definition if [ "$1" = "-p" ] then if [ "$3" = "" ] then if [ "$1" = "-p" ] then ls -A $TACPID 2> /dev/null | grep -c $TACPID > /var/tmp/nspid-new fi fi fi if [ "$1" = "-p" ] then if [ "$3" = "" ] then if [ "$1" = "-p" ] then if [ "`cat /var/tmp/nspid-new`" = "0" ] then /usr/sbin/tac_plus -C /etc/tacacs.conf -p `echo $PORT`;echo "No PID File, Starting tac_plus on port `echo $PORT`, PID `cat $TACPID`";exit fi fi fi fi # Starting tac_plus on non-standard port if a PID File Exists using the default config ps -aux | awk '{print $2}' | grep -c "`cat $TACPID`" > /var/tmp/nspid 2>$1 /dev/null if [ "$1" = "-p" ] then if [ "$3" = "" ] then if [ "$1" = "-p" ] then if [ "`cat /var/tmp/nspid`" -gt "0" ]; then echo "tac_plus is up PID `cat $TACPID`";exit elif [ "`cat /var/tmp/nspid`" = "0" ]; then echo "tac_plus is down";/usr/sbin/tac_plus -C /etc/tacacs.conf -p `echo $PORT`;echo "Restarting tac_plus PID `cat /etc/tac_plus.pid`";exit fi fi fi fi # Starting tac_plus on non-standatd port if no PID file exists with config file definition echo 1 if [ "$1" = "-c" ] then ls -A $TACPID 2> /dev/null | grep -c $TACPID > /var/tmp/nspidconf-new fi if [ "$1" = "-c" ] then if [ "`cat /var/tmp/nspidconf-new`" = "0" ] then /usr/sbin/tac_plus -C $3 -p `echo $PORT`;echo "No PID File, Starting tac_plus on port `echo $PORT`, PID `cat $TACPID`";exit fi fi ################## echo 2 if [ "$1" = "-c" ] then ls -A $TACPID 2> /dev/null | grep -c $TACPID > /var/tmp/nspidconf-new fi echo 3 if [ "$1" = "-c" ] then if [ "`cat /var/tmp/nspidconf-new`" = "1" ] then ps -aux | awk '{print $2}' > /var/tmp/confpid fi fi if [ "$1" = "-c" ] then grep -c `cat $TACPID` /var/tmp/confpid > /var/tmp/nspidconf-ext fi if [ "$1" = "-c" ] then if [ `cat /var/tmp/nspidconf-ext` = "1" ] then echo "tac_plus listening on port `echo $2` Is Up PID `cat $TACPID` ";exit fi fi if [ "$1" = "-c" ] then if [ `cat /var/tmp/nspidconf-ext` = "0" ] then echo "tac_plus is down";/usr/sbin/tac_plus -C $3 -p `echo $PORT`;echo "Restarting tac_plus istening on port `echo $2` PID `cat /etc/tac_plus.pid`" fi fi echo 5 if [ "$1" = "-f" ] then echo "clearing PID files"; rm -rf /etc/tac_plus.pi*;exit fi if [ "$1" = "-h" ] then clear;echo " ###################### checktacplus ##################### Here is a complete list of command flags and functions: Start the default service = checktacplus Stop the default service = checktacplus Ðk Reload the configuration of the default service = checktacplus -r Start an instance running on a non-standard port, using the default configuration = checktacplus Ðp Start an instance running on a non-standard port, using an alternative configuration file = checktacplus Ðc Reload an instance running on a non-standard port = checktacplus Ðpr Stop an instance running on a non-standard port = checktacplus Ðkp Review the help information and command options = -h " | more fi;exit