head 1.2; access; symbols; locks alexis:1.2; strict; comment @# @; 1.2 date 98.08.27.15.38.42; author alexis; state Exp; branches; next 1.1; 1.1 date 98.08.07.11.36.41; author alexis; state Exp; branches; next ; desc @send news script using suck @ 1.2 log @*** empty log message *** @ text @#!SCRIPTSHELLCMD_MARKER PATH=/bin:/usr/bin PROGNAME=`basename $0` ############################################################################### # # # LINK USE COUNTER # # # ############################################################################### ############################################################################### # # Things you should know about this script: # # It is stored under RCS! Keep it that way! If you want a history of # changes made to this script then refer to rlog(1) - don't look here! # ############################################################################### ############################################################################### # # CONFIGURABLE STUFF STARTS HERE # ############################################################################### ############################################################################### # # CONFIGURABLE STUFF ENDS HERE # ############################################################################### VERSION="PATCHLEVEL_MARKER" # $Id: usecnt.in,v 1.1 1998/08/07 11:36:41 alexis Exp alexis $ SNDMSG=LCLSBINDIR_MARKER/sndmsg ############################################################################### # # MAIN FUNCTION (called from very bottom of script) # ############################################################################### main() { ########################################################################### # # PROCESS OPTIONS # ########################################################################### while [ "X$1" != X ]; do case "$1" in -V) if expr "$VERSION" : 'P.*R$' > /dev/null; then warning "this is a development version; use 'ident' for version information" exit 1 else echo "$PROGNAME version $VERSION" exit 0 fi ;; -d) [ "X$2" = X ] && usage VERBOSE_LEVEL=$2 shift ;; -v) VERBOSE_LEVEL=3 ;; -*) usage ;; *) break ;; esac shift done # One argument required - the network interface to check [ "X$1" = X -o "X$2" != X ] && usage # Are locks required? No. This script should run very quickly. ########################################################################### # # GET USE COUNT # ########################################################################### info "getting use count for $1" ### # This is a cheat! This program isn't finished, so all we do is ### # generate a changing number and return that! ### USECOUNT=`sed 's/\..*//' < /proc/uptime` # This uses the packet count on the specified interface from /proc. USECOUNT=`sed -n "s/^[ ]*$1:[ ][ ]*\([0-9][0-9]*\)[ ][ ]*.*\$/\1/p" < /proc/net/dev` info "use count is $USECOUNT" $SNDMSG 39 $USECOUNT } gen_lock_file_name() { echo LOCKDIR_MARKER/$PROGNAME.pid } usage() { { echo "Usage: $PROGNAME [ -d | -v ] " echo " $PROGNAME -V" } >&2 exit 1 } ############################################################################### # # RESILIANT MESSAGING FUNCTIONS # ############################################################################### internal() { MSG="INTERNAL ERROR: $*" DATE=`date` # echo it so that the user can see it or cron can trap it (split line # to avoid confusing 'ident') echo "$PROGNAME: \ $MSG" >&2 # try to write it into $LOG_FILE if that's defined - other message types # treat unwritable but defined LOG_FILE as an error ( echo "$DATE: \ $MSG" >> ${LOG_FILE:-/dev/null} ) 2>/dev/null # try to syslog it - other message types are only syslog'ed if there is # no controlling terminal (as when run from 'at' or 'cron') logger -i -p local0.alert -t $PROGNAME "$MSG" # try to log it on the console echo "$DATE: \ $MSG" > /dev/console exit 2 } error() { DO_EXIT=${ERRORS_CAUSE_EXITS:-true} STDIN=false while :; do case "$1" in -) STDIN=true ;; -e) DO_EXIT=true ;; -ne) DO_EXIT=false ;; -*) internal "invalid option to error() '$1'" ;; *) break ;; esac shift done if [ ${VERBOSE_LEVEL:-2} -ge 1 ]; then DATE=`date` { { [ $STDIN = false ] && echo "$@@"; } || cat; } | while read LINE; do MSG="ERROR: $LINE" ( echo "$DATE: \ $MSG" >> ${LOG_FILE:-/dev/null} ) 2>/dev/null || internal "log file $LOG_FILE not writable!" { [ -t 2 ] && echo "$PROGNAME: \ $MSG" >&2; } || logger -i -p $FACILITY.err -t $PROGNAME "$MSG" done fi [ $DO_EXIT = false ] && return 1 exitdel exit 1 } warning() { STDIN=false while :; do case "$1" in -) STDIN=true ;; -*) internal "invalid option to error() '$1'" ;; *) break ;; esac shift done if [ ${VERBOSE_LEVEL:-2} -ge 2 ]; then DATE=`date` { { [ $STDIN = false ] && echo "$@@"; } || cat; } | while read LINE; do MSG="WARNING: $LINE" ( echo "$DATE: \ $MSG" >> ${LOG_FILE:-/dev/null} ) 2>/dev/null || internal "log file $LOG_FILE not writable!" { [ -t 2 ] && echo "$PROGNAME: \ $MSG" >&2; } || logger -i -p $FACILITY.warning -t $PROGNAME "$MSG" done fi return 0 } debug() { STDIN=false while :; do case "$1" in -) STDIN=true ;; -*) internal "invalid option to error() '$1'" ;; *) break ;; esac shift done LEVEL=$1 shift if [ ${VERBOSE_LEVEL:-2} -ge $LEVEL ]; then DATE=`date` { { [ $STDIN = false ] && echo "$@@"; } || cat; } | while read LINE; do MSG="DEBUG[$LEVEL]: $LINE" ( echo "$DATE: \ $MSG" >> ${LOG_FILE:-/dev/null} ) 2>/dev/null || internal "log file $LOG_FILE not writable!" { [ -t 2 ] && echo "$PROGNAME: \ $MSG" >&2; } || logger -i -p $FACILITY.debug -t $PROGNAME "$MSG" done fi return 0 } info() { STDIN=false while :; do case "$1" in -) STDIN=true ;; -*) internal "invalid option to error() '$1'" ;; *) break ;; esac shift done if [ ${VERBOSE_LEVEL:-2} -ge 3 ]; then DATE=`date` { { [ $STDIN = false ] && echo "$@@"; } || cat; } | while read LINE; do MSG="INFO: $LINE" ( echo "$DATE: \ $MSG" >> ${LOG_FILE:-/dev/null} ) 2>/dev/null || internal "log file $LOG_FILE not writable!" { [ -t 2 ] && echo "$PROGNAME: \ $MSG" >&2; } || logger -i -p $FACILITY.info -t $PROGNAME "$MSG" done fi return 0 } ############################################################################### # # GENERIC SUPPORT FUNCTIONS (not specifically related to backup task) # ############################################################################### locatecmd() { for POSSCMD in $*; do [ X`whichcmd $POSSCMD` != X ] && { echo $POSSCMD; return 0; } done return 1 } whichcmd() { for DIR in `echo $PATH | sed 's/:/ /g'`; do [ -x $DIR/$1 ] && { echo $DIR/$1; return 0; } done return 1 } ############################################################################### # # TEMPORARY FILE MANAGEMENT FUNCTIONS # ############################################################################### delonexit() { DELONEXIT="$DELONEXIT $*" } dontdelonexit() { for FILE in $*; do DELONEXIT=`echo $DELONEXIT | sed "s@@$FILE@@@@g"` done } exitdel() { debug 5 "cleaning up" rm -f $DELONEXIT } sighandler() { warning "signal recieved, clearing up and exiting" exitdel exit 3 } ############################################################################### # # LOCKING ROUTINES # ############################################################################### lock() { debug 5 "lock: locking $1" LOCKFILE=`gen_lock_file_name $1` { echo $$ > $LOCKFILE.$$; } 2>/dev/null || error -e "can't create lock" ln $LOCKFILE.$$ $LOCKFILE 2>/dev/null && { rm $LOCKFILE.$$; return 0; } HOLDING_PID=`cat $LOCKFILE` [ "X$HOLDING_PID" = X ] && { rm $LOCKFILE.$$; error -e "empty lockfile: $LOCKFILE"; } [ -d /proc/$HOLDING_PID ] && { rm $LOCKFILE.$$; error -e "program running already! (pid=$HOLDING_PID)"; } info "removing stale lock (pid=$HOLDING_PID)" rm -f $LOCKFILE ln $LOCKFILE.$$ $LOCKFILE 2>/dev/null && { rm $LOCKFILE.$$; return 0; } rm $LOCKFILE.$$ error -e "couldn't lock after removing stale lockfile" } unlock() { debug 5 "unlock: unlocking $1" LOCKFILE=`gen_lock_file_name $1` rm -f $LOCKFILE } umask 022 main "$@@" exit $? @ 1.1 log @Initial revision @ text @d33 1 a33 1 # $Id: sndmail-sendmail.in,v 1.5 1998/02/05 12:27:22 alexis Exp $ d70 1 a70 1 # One argument required - the host to use for the check d82 8 a89 3 # This is a cheat! This program isn't finished, so all we do is # generate a changing number and return that! USECOUNT=`sed 's/\..*//' < /proc/uptime` @