From - Wed Mar 13 10:18:09 1996 Newsgroups: alt.sources Path: glukr!KremlSun!news1.relcom.eu.net!news.spb.su!news.eunet.fi!EU.net!newsfeed.internetmci.com!howland.reston.ans.net!ix.netcom.com!netcom.com!darkfox From: darkfox@netcom.com (Johnson Michael Earls) Subject: netwatch (1/1) - UNIX system monitoring scripts Message-ID: Organization: NETCOM On-line Communication Services (408 261-4700 guest) Date: Mon, 11 Mar 1996 17:32:41 GMT Lines: 1982 Sender: darkfox@netcom21.netcom.com Hello all, This is the first posting of netwatch, a set of system monitoring scripts for UNIX. If you download this and use it, please let me know (darkfox@netcom.com). If there are no serious bugs found from this posting, I will send it to comp.sources.unix in about a month. - Johnson Earls darkfox@netcom.com - - - - - - - - - - - - - - README: cut here - - - - - - - - - - - - - - NetWatch 1.0 (c) Copyright 1996 Johnson Earls (darkfox@netcom.com) - - - NetWatch is known to work under Solaris 2.x, and the test programs are known to work under both Solaris 2.x and SunOS 4.1.3. If you have problems running under another version of UNIX, please let me know what the problem is, and what the fix is if you found one! When reporting any problems to me, please include any additional support information that you can, including configuration files, error messages, etc. - - - NetWatch is a set of system monitoring scripts designed to run out of a cron job, emailing results to the system administrators. It includes the following "tests": homedirs (also called "servers") This checks the %capacity of filesystems, giving warnings for filesystems that are full or mostly full. hosts This simply checks the availability of a list of hosts loadavg This reports high load averages. logfiles Each time this test runs, it displays lines that have been added to system log files since the last run. printers Reports when print servers are "stuck" (i.e. have more than a certain number of jobs waiting to print) processes Reports when specific processes are running too many or too few times. Each test has its own configuration file and data file. Each test (except logfiles) will normally only report changes since the last time the test was run; the "-a" flag forces each test to give a full report. The configuration files are pretty much self-documenting; the data files are described in more detail in the next section. - - - Simple Installation Steps: 1) Compile 'bin/timeout' from 'bin/timeout.c'. This should compile with any unix ANSI C compiler. 2) Edit Configuration files in 'lib', correcting settings for your system. 3) Edit data files in 'lib'. (See 'doc/NetWatch' for info) Remove any data files for tests you don't wish to run. 4) Run netwatch manually, or add it to a crontab. - - - Document Revision Information $Revision: 1.0 $ $Author: jearls $ $Date: 1996/03/08 19:21:12 $ $Log: README,v $ Revision 1.0 1996/03/08 19:21:12 jearls Initial revision - - - - - - - - - - - - - - - - cut here - - - - - - - - - - - - - - - - #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'README' <<'END_OF_FILE' XNetWatch 1.0 X(c) Copyright 1996 Johnson Earls (darkfox@netcom.com) X X - - - X X NetWatch is known to work under Solaris 2.x, and the test programs Xare known to work under both Solaris 2.x and SunOS 4.1.3. If you have Xproblems running under another version of UNIX, please let me know what Xthe problem is, and what the fix is if you found one! X X When reporting any problems to me, please include any additional Xsupport information that you can, including configuration files, error Xmessages, etc. X X - - - X XNetWatch is a set of system monitoring scripts designed to run out of a Xcron job, emailing results to the system administrators. It includes Xthe following "tests": X X homedirs (also called "servers") X This checks the %capacity of filesystems, giving X warnings for filesystems that are full or mostly full. X X hosts This simply checks the availability of a list of hosts X X loadavg This reports high load averages. X X logfiles Each time this test runs, it displays lines that have X been added to system log files since the last run. X X printers Reports when print servers are "stuck" (i.e. have more X than a certain number of jobs waiting to print) X X processes Reports when specific processes are running too many or X too few times. X XEach test has its own configuration file and data file. Each test X(except logfiles) will normally only report changes since the last time Xthe test was run; the "-a" flag forces each test to give a full Xreport. The configuration files are pretty much self-documenting; the Xdata files are described in more detail in the next section. X X - - - X XSimple Installation Steps: X X1) Compile 'bin/timeout' from 'bin/timeout.c'. X This should compile with any unix ANSI C compiler. X X2) Edit Configuration files in 'lib', correcting settings X for your system. X X3) Edit data files in 'lib'. (See 'doc/NetWatch' for info) X Remove any data files for tests you don't wish to run. X X4) Run netwatch manually, or add it to a crontab. X X - - - X XDocument Revision Information X X$Revision: 1.0 $ X $Author: jearls $ X $Date: 1996/03/08 19:21:12 $ X X$Log: README,v $ XRevision 1.0 1996/03/08 19:21:12 jearls XInitial revision X END_OF_FILE if test 2401 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi # end of 'README' fi if test -f 'MANIFEST' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'MANIFEST'\" else echo shar: Extracting \"'MANIFEST'\" \(2108 characters\) sed "s/^X//" >'MANIFEST' <<'END_OF_FILE' X File Name Archive # Description X----------------------------------------------------------- X README 1 Simple README / insallation instructions X MANIFEST 1 This shipping list X netwatch 1 NetWatch directory X netwatch/bin 1 Directory containing the scripts X netwatch/bin/netwatch 1 The master netwatch script X netwatch/bin/netwatch.homedirs 1 ..home directory sizes X netwatch/bin/netwatch.hosts 1 ..host up-or-down status X netwatch/bin/netwatch.loadavg 1 ..load average checker X netwatch/bin/netwatch.logfiles 1 ..log file reporter X netwatch/bin/netwatch.printers 1 ..printer status X netwatch/bin/netwatch.processes 1 ..process count checker X netwatch/bin/netwatch.servers 1 ..server directory sizes X netwatch/bin/timeout.c 1 the source to the 'timeout' program X netwatch/doc 1 Directory containing the (scanty) documentation X netwatch/doc/NetWatch.doc 1 Simple setup / configuration instructions X netwatch/lib 1 Directory containing configuration / data files X netwatch/lib/Configuration 1 Master configuration file X netwatch/lib/Configuration.homedirs 1 ..Configuration for homedirs test X netwatch/lib/Configuration.hosts 1 ..Configuration for hosts test X netwatch/lib/Configuration.loadavg 1 ..Configuration for loadavg test X netwatch/lib/Configuration.logfiles 1 ..Configuration for logfiles test X netwatch/lib/Configuration.printers 1 ..Configuration for printers test X netwatch/lib/Configuration.processes 1 ..Configuration for processes test X netwatch/lib/Configuration.servers 1 ..Configuration for servers test X netwatch/sample 1 Sample data files X netwatch/sample/homedirs 1 ..data file for homedirs test X netwatch/sample/hosts 1 ..data file for hosts test X netwatch/sample/loadavg 1 ..data file for loadavg test X netwatch/sample/logfiles 1 ..data file for logfiles test X netwatch/sample/printers 1 ..data file for printers test X netwatch/sample/processes 1 ..data file for processes test X netwatch/sample/servers 1 ..data file for servers test END_OF_FILE if test 2108 -ne `wc -c <'MANIFEST'`; then echo shar: \"'MANIFEST'\" unpacked with wrong size! fi # end of 'MANIFEST' fi if test ! -d 'netwatch' ; then echo shar: Creating directory \"'netwatch'\" mkdir 'netwatch' fi if test ! -d 'netwatch/bin' ; then echo shar: Creating directory \"'netwatch/bin'\" mkdir 'netwatch/bin' fi if test -f 'netwatch/bin/netwatch' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'netwatch/bin/netwatch'\" else echo shar: Extracting \"'netwatch/bin/netwatch'\" \(5658 characters\) sed "s/^X//" >'netwatch/bin/netwatch' <<'END_OF_FILE' X#!/bin/sh X# NetWatch 1.0 X# (c) Copyright 1996 by Johnson Earls (darkfox@netcom.com) X# X# netwatch - main program X# X# usage: X# netwatch [ ] X# X# options: X# -a Report all test output, rather than just the summary X# results that have changed since the last run. X# -C Use as the configuration directory. If netwatch X# is run as /XYZ/bin/netwatch, then this will default to X# /XYZ/lib; otherwise it will default to X# /usr/local/lib/netwatch. X# -D Use as the data / test-results directory. This X# defaults to the configuration directory. X# -m Send results to . If is -, then X# output to stdout rather than sending mail. Default X# is set by the MAILTO option in the configuration file. X# -M Change 'NetWatch' in the mail subject line to . X# -n Don't run the program. (See 'netwatch -h' for X# a list of the default test programs). X# -x Run the program. should be the full X# pathname of the test program. See netwatch docs X# for a description of how to write test programs. X# X# -- REVISION CONTROL -- X# X# $Revision: 1.0 $ X# $Author: jearls $ X# $Date: 1996/03/08 18:18:39 $ X# X# $Log: netwatch,v $ X# Revision 1.0 1996/03/08 18:18:39 jearls X# Initial revision X# X X# --- find where the program is running X Xprogdir=`dirname $0` Xprogdir=`cd ${progdir}; pwd` Xprogname=`basename $0` Xprog=${progdir}/${progname} X X# --- subroutines X X### usage X# print a usage message, prefixed by if specified Xusage() { X case "$1" in X ?*) echo "$1" 1>&2; echo "" 1>&2;; X esac X X cat << USAGE_EOF 1>&2 XUsage: X ${progname} [ ... ] X XOptions: X -a Report all test output, rather than just the summary X results that have changed since the last run. X -C Use as the configuration directory. If ${progname} X is run as /XYZ/bin/${progname}, then this will default to X /XYZ/lib; otherwise it will default to X /usr/local/lib/${progname}. X -D Use as the data / test-results directory. This X defaults to the configuration directory. X -m Send results to . If is -, then X output to stdout rather than sending mail. Default X is set by the MAILTO option in the configuration file. X -M Change 'NetWatch' in the mail subject line to . X -n Don't run the program. (See '${progname} -h' for X a list of the default test programs). X -x Run the program. should be the full X pathname of the test program. See ${progname} docs X for a description of how to write test programs. X XCurrently installed test programs: X ${TESTS} X XUSAGE_EOF X X exit 22 X} X X# --- find the test scripts that exist X XTESTS="x:" X Xfor test in ${prog}.* Xdo X testname=`expr x${test} : x${prog}'[.]\(.*\)'` X [ -x ${test} ] && TESTS="${TESTS}:${testname}" Xdone X XTESTS=`echo ${TESTS} | cut -d: -f3- | tr ':' ' '` XRUN=${TESTS} X X# --- parse the command line arguments X XcmdSUBJ="NetWatch" X Xwhile : Xdo X case "$1" in X -a) cmdALL="-a";; X -C) cmdCONFIG="$2"; shift;; X -D) cmdDATA="$2"; shift;; X -h) usage;; X -m) cmdMAILTO="$2"; shift;; X -M) cmdSUBJ="$2"; shift;; X -n) case " ${RUN} " in X *" $2 "*) X RUN=`echo " ${RUN} " | sed -e 's/ '"$2"' / /' -e 's/^ //' -e 's/ $//'` X ;; X *) X case " ${TESTS} " in X *" $2 "*) ;; X *) X usage "${progname} No such test program "'"'"$2"'"'"!" X esac X esac X shift X ;; X -x) echo "-x not supported yet, sorry!" 1>&2; echo " skipping test "'"'"$2"'"'"..." 1>&2; shift;; X -*) usage "${progname}: Unknown option "'"'"$1"'"'"!";; X *) break;; X esac X shift Xdone X Xif [ -z "${cmdCONFIG}" ] Xthen X cmdCONFIG=/usr/local/lib X case "${progdir}" in X *"/bin") X cmdCONFIG="`dirname \"${progdir}\"`/lib" X esac X [ -d "${cmdCONFIG}/${progname}" ] && cmdCONFIG="${cmdCONFIG}/${progname}" Xfi X XconfigDir="${cmdCONFIG}" X Xif [ -z "${cmdDATA}" ] Xthen X dataDir="${configDir}" Xelse X dataDir="${cmdDATA}" Xfi X X[ -x "${configDir}/Configuration" ] && configFile="${configDir}/Configuration" || usage "No configuration file found!" X X. "${configFile}" X Xcase "${cmdMAILTO}" in X "") realMAILTO="${MAILTO}";; X *) realMAILTO="${cmdMAILTO}";; Xesac X Xcase "${MAILTO}" in X "") MAILTO="${progname}" Xesac X XPATH="${progdir}:/bin:/usr/bin:/usr/ucb:/usr/sbin" X Xexport configFile configDir dataDir realMAILTO PATH X Xfor test in ${RUN} Xdo X testConfig="${configDir}/Configuration.${test}" X dataFile="${dataDir}/${test}" X testProg="${prog}.${test}" X export testConfig test dataFile testProg X [ -x "${testConfig}" -a -s "${dataFile}" ] && ( X TESTNAME="${test}" X . "${testConfig}" X header="### ${cmdSUBJ} ${TESTNAME} test started at `date +'%d %b %Y %H:%M'`" X case "${cmdALL}" in X "") subj="${cmdSUBJ} ${TESTNAME} summary";; X *) subj="Full ${cmdSUBJ} ${TESTNAME} results";; X esac X ( exec "${prog}.${test}" ${cmdALL} > /tmp/${progname}.$$."${test}" 2>&1 ) X [ -s /tmp/${progname}.$$."${test}" ] && ( X echo "${header}" X echo "" X cat /tmp/${progname}.$$."${test}" X ) | ${MAIL} -s "${subj}" ${realMAILTO} X rm -f /tmp/${progname}.$$."${test}" X ) /dev/null & Xdone END_OF_FILE if test 5658 -ne `wc -c <'netwatch/bin/netwatch'`; then echo shar: \"'netwatch/bin/netwatch'\" unpacked with wrong size! fi chmod +x 'netwatch/bin/netwatch' # end of 'netwatch/bin/netwatch' fi if test -f 'netwatch/bin/netwatch.homedirs' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'netwatch/bin/netwatch.homedirs'\" else echo shar: Extracting \"'netwatch/bin/netwatch.homedirs'\" \(1873 characters\) sed "s/^X//" >'netwatch/bin/netwatch.homedirs' <<'END_OF_FILE' X#!/bin/sh X# NetWatch 1.0 X# (c) Copyright 1996 by Johnson Earls (darkfox@netcom.com) X# X# home directory server check for netwatch X# X# -- REVISION CONTROL -- X# X# $Revision: 1.0 $ X# $Author: jearls $ X# $Date: 1996/03/08 18:18:39 $ X# X# $Log: netwatch.homedirs,v $ X# Revision 1.0 1996/03/08 18:18:39 jearls X# Initial revision X# X X### READ CONFIGURATION ### X X. "${configFile}"; X. "${testConfig}"; X X[ -z "$REMOTEUSER" ] && REMOTEUSER=`id | tr '()' '::' | cut -d: -f2` X X### SUBROUTINES ### X Xcheckdir() { X host="$1" X dir="$2" X if checkhost "$host" X then X set x `rsh -l $REMOTEUSER "$host" '( cd /; test -f /etc/vfstab && df -k "'"${dir}"'" || df "'"${dir}"'" ) | awk '"'"'$6 == "'"${dir}"'" {print $5}'"'"' | tr -d "%"'` X if [ $2 -gt $SIZEFULL ] X then X echo "at $2%" X else X if [ $2 -gt $SIZEOK ] X then X echo "over $SIZEOK%" X else X echo "ok" X fi X fi X else X echo "down" X fi X} X X### MAIN ROUTINE ### X Xoptions='a' X Xwhile getopts ${options} opt Xdo X case ${opt} in X X a) all="-a" X ;; X X esac Xdone X Xlockfile ${dataFile}.lock || { exit 11; } Xecho $$ >> ${dataFile}.lock X Xif [ -r "${dataFile}" ] Xthen X cp /dev/null ${dataFile}.tmp X homedirs=`awk '{print $1 ":" $2}' ${dataFile}` X for dir in ${homedirs} X do X oIFS="$IFS"; IFS=":"; set x:$dir; IFS="$oIFS" X server="$2" X dir="$3" X oldstat="`awk '$1 == \"'${server}'\" && $2 == \"'${dir}'\"' ${dataFile} | cut -d' ' -f3-`" X newstat="`checkdir ${server} ${dir}`" X case "${all}${newstat}" in X "${oldstat}") ;; X "${all}down") newstat="${oldstat}";; X *) echo "${server}:${dir} is ${newstat}!" X esac X echo "${server} ${dir} ${newstat}" >> ${dataFile}.tmp X done X mv ${dataFile} ${dataFile}.old X mv ${dataFile}.tmp ${dataFile} Xfi X Xunlockfile ${dataFile}.lock || { echo "${test}: my lock file has been broken!" 1>&2; exit 11; } END_OF_FILE if test 1873 -ne `wc -c <'netwatch/bin/netwatch.homedirs'`; then echo shar: \"'netwatch/bin/netwatch.homedirs'\" unpacked with wrong size! fi chmod +x 'netwatch/bin/netwatch.homedirs' # end of 'netwatch/bin/netwatch.homedirs' fi if test -f 'netwatch/bin/netwatch.hosts' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'netwatch/bin/netwatch.hosts'\" else echo shar: Extracting \"'netwatch/bin/netwatch.hosts'\" \(1105 characters\) sed "s/^X//" >'netwatch/bin/netwatch.hosts' <<'END_OF_FILE' X#!/bin/sh X# NetWatch 1.0 X# (c) Copyright 1996 by Johnson Earls (darkfox@netcom.com) X# X# hosts check for netwatch X# X# -- REVISION CONTROL -- X# X# $Revision: 1.0 $ X# $Author: jearls $ X# $Date: 1996/03/08 18:18:39 $ X# X# $Log: netwatch.hosts,v $ X# Revision 1.0 1996/03/08 18:18:39 jearls X# Initial revision X# X X### READ CONFIGURATION ### X X. "${configFile}"; X. "${testConfig}"; X X### MAIN ROUTINE ### X Xoptions='a' X Xwhile getopts ${options} opt Xdo X case ${opt} in X X a) all="-a" X ;; X X esac Xdone X Xlockfile ${dataFile}.lock || { exit 11; } Xecho $$ >> ${dataFile}.lock X Xcp /dev/null ${dataFile}.tmp Xhosts=`awk '{print $1}' ${dataFile}` Xfor host in ${hosts} Xdo X oldstat=`awk '$1 == "'${host}'" {print $2}' ${dataFile}` X if checkhost ${host} X then X newstat=up X else X newstat=down X fi X case "${all}${newstat}" in X "${oldstat}") ;; X *) echo "${host} is ${newstat}!" X esac X echo "${host} ${newstat}" >> ${dataFile}.tmp Xdone Xmv ${dataFile} ${dataFile}.old Xmv ${dataFile}.tmp ${dataFile} X Xunlockfile ${dataFile}.lock || { echo "${test}: my lock file has been broken!" 1>&2; exit 11; } END_OF_FILE if test 1105 -ne `wc -c <'netwatch/bin/netwatch.hosts'`; then echo shar: \"'netwatch/bin/netwatch.hosts'\" unpacked with wrong size! fi chmod +x 'netwatch/bin/netwatch.hosts' # end of 'netwatch/bin/netwatch.hosts' fi if test -f 'netwatch/bin/netwatch.loadavg' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'netwatch/bin/netwatch.loadavg'\" else echo shar: Extracting \"'netwatch/bin/netwatch.loadavg'\" \(1845 characters\) sed "s/^X//" >'netwatch/bin/netwatch.loadavg' <<'END_OF_FILE' X#!/bin/sh X# NetWatch 1.0 X# (c) Copyright 1996 by Johnson Earls (darkfox@netcom.com) X# X# load average check for netwatch X# X# -- REVISION CONTROL -- X# X# $Revision: 1.0 $ X# $Author: jearls $ X# $Date: 1996/03/08 18:18:39 $ X# X# $Log: netwatch.loadavg,v $ X# Revision 1.0 1996/03/08 18:18:39 jearls X# Initial revision X# X X### READ CONFIGURATION ### X X. "${configFile}"; X. "${testConfig}"; X X### SUBROUTINES ### X Xcheckload() { X host="$1" X X if ping ${host} ${PINGTIMEOUT} > /dev/null 2>&1 X then X set x `timeout ${RUPTIMEOUT} rup ${host} 2>/dev/null`; shift 2 X case "$1" in X "up") X load1=`echo $7 | tr -d ',.'` X load5=`echo $8 | tr -d ',.'` X load15=`echo $9 | tr -d ',.'` X if [ "${load1}" -gt "${MAXLOAD1}" ] X then X echo "1 min load $7" X elif [ "${load5}" -gt "${MAXLOAD5}" ] X then X echo "5 min load $8" X elif [ "${load15}" -gt "${MAXLOAD15}" ] X then X echo "15 min load $9" X else X echo "ok" X fi X return 0 X esac X fi X echo "down" X return 1 X} X X### MAIN ROUTINE ### X Xoptions='a' X Xwhile getopts ${options} opt Xdo X case ${opt} in X X a) all="-a" X ;; X X esac Xdone X Xlockfile ${dataFile}.lock || { exit 11; } Xecho $$ >> ${dataFile}.lock X Xcp /dev/null ${dataFile}.tmp Xhosts=`awk '{print $1}' ${dataFile}` Xfor host in ${hosts} Xdo X oldstat=`awk '$1 == "'${host}'" {print $2}' ${dataFile}` X newstat=`checkload ${host}` X case "${all}${newstat}" in X "${oldstat}") ;; X "${all}down") newstat="${oldstat}";; X "*load*") echo "${host} has ${newstat}!";; X *) echo "${host} is ${newstat}!" X esac X echo "${host} ${newstat}" >> ${dataFile}.tmp Xdone Xmv ${dataFile} ${dataFile}.old Xmv ${dataFile}.tmp ${dataFile} X Xunlockfile ${dataFile}.lock || { echo "${test}: my lock file has been broken!" 1>&2; exit 11; } END_OF_FILE if test 1845 -ne `wc -c <'netwatch/bin/netwatch.loadavg'`; then echo shar: \"'netwatch/bin/netwatch.loadavg'\" unpacked with wrong size! fi chmod +x 'netwatch/bin/netwatch.loadavg' # end of 'netwatch/bin/netwatch.loadavg' fi if test -f 'netwatch/bin/netwatch.logfiles' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'netwatch/bin/netwatch.logfiles'\" else echo shar: Extracting \"'netwatch/bin/netwatch.logfiles'\" \(2361 characters\) sed "s/^X//" >'netwatch/bin/netwatch.logfiles' <<'END_OF_FILE' X#!/bin/sh X# NetWatch 1.0 X# (c) Copyright 1996 by Johnson Earls (darkfox@netcom.com) X# X# log files check for netwatch X# X# -- REVISION CONTROL -- X# X# $Revision: 1.0 $ X# $Author: jearls $ X# $Date: 1996/03/08 18:18:39 $ X# X# $Log: netwatch.logfiles,v $ X# Revision 1.0 1996/03/08 18:18:39 jearls X# Initial revision X# X X### READ CONFIGURATION ### X X. "${configFile}"; X. "${testConfig}"; X X[ -z "$REMOTEUSER" ] && REMOTEUSER=`id | tr '()' '::' | cut -d: -f2` X X### SUBROUTINES ### X Xchecklogfile() { X case "$1" in X "-a") all="-a"; shift;; X esac X host="$1" X file="$2" X case "$3" in X "") oldlines=0;; X *) oldlines="$3" X esac X X if checkhost "$host" X then X lines=`rsh -l $REMOTEUSER "$host" 'wc -l < "'"${file}"'"'` X lines=`expr $lines + 0` X newlines=`expr $lines - $oldlines` X realnewlines="$newlines" X [ $newlines -lt 0 -o $newlines -gt $MAXLINES ] && newlines=$MAXLINES X case "$all" in X "-a") newlines=$INITLINES X esac X X if [ $lines -gt 0 -a $newlines -gt 0 ] X then X case "$realnewlines" in X "$newlines") echo "$host:$file - $newlines new lines:" >> ${dataFile}.lock;; X -*) echo "$host:$file - new file; displaying $newlines new lines:" >> ${dataFile}.lock;; X *) echo "$host:$file - $realnewlines new lines; displaying $newlines new lines:" >> ${dataFile}.lock;; X esac X rsh -l $REMOTEUSER "$host" tail -$newlines "$file" >> ${dataFile}.lock X echo "" >> ${dataFile}.lock X fi X# else X# echo "$host:$file - $host is down!" >> ${dataFile}.lock X fi X X echo $lines X} X X### MAIN ROUTINE ### X Xoptions='a' X Xwhile getopts ${options} opt Xdo X case ${opt} in X X a) all="-a" X ;; X X esac Xdone X Xlockfile ${dataFile}.lock || { exit 11; } X Xif [ -r "${dataFile}" ] Xthen X cp /dev/null ${dataFile}.tmp X logfiles=`awk '{print $1 ":" $2}' ${dataFile}` X for file in ${logfiles} X do X oIFS="$IFS"; IFS=":"; set x:$file; IFS="$oIFS" X server="$2" X file="$3" X oldlines="`awk '$1 == \"'${server}'\" && $2 == \"'${file}'\"' ${dataFile} | cut -d' ' -f3-`" X newlines="`checklogfile ${all} ${server} ${file} ${oldlines}`" X echo "${server} ${file} ${newlines}" >> ${dataFile}.tmp X done X mv ${dataFile} ${dataFile}.old X mv ${dataFile}.tmp ${dataFile} Xfi X Xcat ${dataFile}.lock X Xunlockfile ${dataFile}.lock || { echo "${test}: my lock file has been broken!" 1>&2; exit 11; } END_OF_FILE if test 2361 -ne `wc -c <'netwatch/bin/netwatch.logfiles'`; then echo shar: \"'netwatch/bin/netwatch.logfiles'\" unpacked with wrong size! fi chmod +x 'netwatch/bin/netwatch.logfiles' # end of 'netwatch/bin/netwatch.logfiles' fi if test -f 'netwatch/bin/netwatch.printers' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'netwatch/bin/netwatch.printers'\" else echo shar: Extracting \"'netwatch/bin/netwatch.printers'\" \(3030 characters\) sed "s/^X//" >'netwatch/bin/netwatch.printers' <<'END_OF_FILE' X#!/bin/sh X# NetWatch 1.0 X# (c) Copyright 1996 by Johnson Earls (darkfox@netcom.com) X# X# printers check for netwatch X# X# -- REVISION CONTROL -- X# X# $Revision: 1.0 $ X# $Author: jearls $ X# $Date: 1996/03/08 18:18:39 $ X# X# $Log: netwatch.printers,v $ X# Revision 1.0 1996/03/08 18:18:39 jearls X# Initial revision X# X X### READ CONFIGURATION ### X X. "${configFile}"; X. "${testConfig}"; X X[ -z "$REMOTEUSER" ] && REMOTEUSER=`id | tr '()' '::' | cut -d: -f2` X X### SUBROUTINES ### X X# runcmd X# run the command Xruncmd() { X timeout ${PRINTERTIMEOUT} rsh -l ${REMOTEUSER} "$@" 2>/dev/null X} X X# checkprinter X# returns status of printer@printserver Xcheckprinter() { X printer="$1" X printserver="$2" X X if checkhost ${printserver} X then X case "`runcmd ${printserver} ls /bin/lpstat`" in X ?*) X# -- sysv print server -- X case "`runcmd ${printserver} /bin/lpstat -p $1 | /bin/head -1`" in X *"idle"* | *"printing"* ) ;; X *) echo "faulted: `/bin/lpstat -p $1 | /bin/sed -n '2p'`"; return;; X esac X if [ `runcmd ${printserver} /bin/lpstat -o $1 | wc -l` -ge ${TOOMANYJOBS} ] X then X echo "stuck" X else X echo "ok" X fi X ;; X# -- sysv print server -- X "") X# -- bsd print server -- X runcmd ${printserver} /usr/ucb/lpq -P${printer} > ${datafile}.tmpout X case "`head -1 ${datafile}.tmpout`" in X *"ready and print"* | "no entries") X if [ `tail +3 ${datafile}.tmpout | wc -l` -ge ${TOOMANYJOBS} ] X then X echo "stuck" X else X echo "ok" X fi X ;; X *) echo "faulted: `head -1 ${datafile}.tmpout`" X esac X rm -f ${datafile}.tmpout X# -- bsd print server -- X ;; X esac X else X echo "down" X fi X} X X### MAIN ROUTINE ### X Xoptions='aP' X Xwhile getopts ${options} opt Xdo X case ${opt} in X X a) all="-a" X ;; X X P) localprinter="-P" X ;; X X esac Xdone X Xshift `expr ${OPTIND} - 1` X Xcase "${localprinter}" in X "-P") X TOOMANYJOBS="$2" X checklocalprinter "$1" X rm -f $0.tmp X ;; X *) X lockfile ${dataFile}.lock || { exit 11; } X echo $$ >> ${dataFile}.lock X X cp /dev/null ${dataFile}.tmp X X printers=`awk '{print $2}' ${dataFile}` X for printer in $printers X do X printserver="`awk '$2 == \"'\"${printer}\"'\" {print $1}' ${dataFile}`" X oldstat="`awk '$2 == \"'\"${printer}\"'\"' ${dataFile} | cut -d' ' -f3-`" X newstat="`checkprinter ${printer} ${printserver}`" X case "${all}${newstat}" in X "${oldstat}") ;; X "${all}down") newstat="${oldstat}";; X *) echo "${printer}@${printserver} is ${newstat}!" X esac X echo "${printserver} ${printer} ${newstat}" >> ${dataFile}.tmp X done X X mv ${dataFile} ${dataFile}.old X mv ${dataFile}.tmp ${dataFile} X X unlockfile ${dataFile}.lock || { echo "${test}: my lock file has been broken!" 1>&2; exit 11; } Xesac END_OF_FILE if test 3030 -ne `wc -c <'netwatch/bin/netwatch.printers'`; then echo shar: \"'netwatch/bin/netwatch.printers'\" unpacked with wrong size! fi chmod +x 'netwatch/bin/netwatch.printers' # end of 'netwatch/bin/netwatch.printers' fi if test -f 'netwatch/bin/netwatch.processes' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'netwatch/bin/netwatch.processes'\" else echo shar: Extracting \"'netwatch/bin/netwatch.processes'\" \(2199 characters\) sed "s/^X//" >'netwatch/bin/netwatch.processes' <<'END_OF_FILE' X#!/bin/sh X# NetWatch 1.0 X# (c) Copyright 1996 by Johnson Earls (darkfox@netcom.com) X# X# printers check for netwatch X# X# -- REVISION CONTROL -- X# X# $Revision: 1.0 $ X# $Author: jearls $ X# $Date: 1996/03/08 18:18:39 $ X# X# $Log: netwatch.processes,v $ X# Revision 1.0 1996/03/08 18:18:39 jearls X# Initial revision X# X X### READ CONFIGURATION ### X X. "${configFile}"; X. "${testConfig}"; X X[ -z "$REMOTEUSER" ] && REMOTEUSER=`id | tr '()' '::' | cut -d: -f2` X X### SUBROUTINES ### X Xcheckproc() { X host="$1" X proc="$2" X min="$3" X max="$4" X X export host proc min max X X if checkhost "$host" X then X set x `timeout ${PSTIMEOUT} rsh -l ${REMOTEUSER} "$host" '( cd /; test -f /etc/vfstab && ( /usr/bin/ps -e | cut -d: -f2- | cut -c4- ) || ( /bin/ps -agxc | cut -c21- ) )' | grep -c '^'"${proc}"'$'` X case "$2" in X "") echo "down";; X *) X if [ "$2" -lt "$min" ] X then X echo "Too few ($2)" X elif [ "$2" -gt "$max" ] X then X echo "Too many ($2)" X else X echo "ok" X fi X esac X else X echo "down" X fi X} X X### MAIN ROUTINE ### X Xoptions='a' X Xwhile getopts ${options} opt Xdo X case ${opt} in X X a) all="-a" X ;; X X esac Xdone X Xshift `expr ${OPTIND} - 1` X Xlockfile ${dataFile}.lock || { exit 11; } Xecho $$ >> ${dataFile}.lock X Xcp /dev/null ${dataFile}.tmp X Xprocinfo=`awk '{print $1 "/" $3 "/" $4 "/" $2 "/" $5}' ${dataFile}` Xfor info in $procinfo Xdo X host="`echo \"$info\" | cut -d/ -f1`" X min="`echo \"$info\" | cut -d/ -f2`" X max="`echo \"$info\" | cut -d/ -f3`" X proc="`echo \"$info\" | cut -d/ -f4`" X oldstat="`echo \"$info\" | cut -d/ -f5`" X realstat="`checkproc \"${host}\" \"${proc}\" \"${min}\" \"${max}\"`" X newstat="`echo \"${realstat}\" | cut -d' ' -f1-2`" X X case "${all}${newstat}" in X "${oldstat}") ;; X "${all}down") newstat="${oldstat}";; X "ok") echo "${host}'s ${proc} is ok!";; X *) echo "${realstat} ${proc} processes on ${host} running!" X esac X echo "${host} ${proc} ${min} ${max} ${newstat}" >> ${dataFile}.tmp Xdone X Xmv ${dataFile} ${dataFile}.old Xmv ${dataFile}.tmp ${dataFile} X Xunlockfile ${dataFile}.lock || { echo "${test}: my lock file has been broken!" 1>&2; exit 11; } END_OF_FILE if test 2199 -ne `wc -c <'netwatch/bin/netwatch.processes'`; then echo shar: \"'netwatch/bin/netwatch.processes'\" unpacked with wrong size! fi chmod +x 'netwatch/bin/netwatch.processes' # end of 'netwatch/bin/netwatch.processes' fi if test -f 'netwatch/bin/netwatch.servers' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'netwatch/bin/netwatch.servers'\" else echo shar: Extracting \"'netwatch/bin/netwatch.servers'\" \(1873 characters\) sed "s/^X//" >'netwatch/bin/netwatch.servers' <<'END_OF_FILE' X#!/bin/sh X# NetWatch 1.0 X# (c) Copyright 1996 by Johnson Earls (darkfox@netcom.com) X# X# home directory server check for netwatch X# X# -- REVISION CONTROL -- X# X# $Revision: 1.0 $ X# $Author: jearls $ X# $Date: 1996/03/08 18:18:39 $ X# X# $Log: netwatch.homedirs,v $ X# Revision 1.0 1996/03/08 18:18:39 jearls X# Initial revision X# X X### READ CONFIGURATION ### X X. "${configFile}"; X. "${testConfig}"; X X[ -z "$REMOTEUSER" ] && REMOTEUSER=`id | tr '()' '::' | cut -d: -f2` X X### SUBROUTINES ### X Xcheckdir() { X host="$1" X dir="$2" X if checkhost "$host" X then X set x `rsh -l $REMOTEUSER "$host" '( cd /; test -f /etc/vfstab && df -k "'"${dir}"'" || df "'"${dir}"'" ) | awk '"'"'$6 == "'"${dir}"'" {print $5}'"'"' | tr -d "%"'` X if [ $2 -gt $SIZEFULL ] X then X echo "at $2%" X else X if [ $2 -gt $SIZEOK ] X then X echo "over $SIZEOK%" X else X echo "ok" X fi X fi X else X echo "down" X fi X} X X### MAIN ROUTINE ### X Xoptions='a' X Xwhile getopts ${options} opt Xdo X case ${opt} in X X a) all="-a" X ;; X X esac Xdone X Xlockfile ${dataFile}.lock || { exit 11; } Xecho $$ >> ${dataFile}.lock X Xif [ -r "${dataFile}" ] Xthen X cp /dev/null ${dataFile}.tmp X homedirs=`awk '{print $1 ":" $2}' ${dataFile}` X for dir in ${homedirs} X do X oIFS="$IFS"; IFS=":"; set x:$dir; IFS="$oIFS" X server="$2" X dir="$3" X oldstat="`awk '$1 == \"'${server}'\" && $2 == \"'${dir}'\"' ${dataFile} | cut -d' ' -f3-`" X newstat="`checkdir ${server} ${dir}`" X case "${all}${newstat}" in X "${oldstat}") ;; X "${all}down") newstat="${oldstat}";; X *) echo "${server}:${dir} is ${newstat}!" X esac X echo "${server} ${dir} ${newstat}" >> ${dataFile}.tmp X done X mv ${dataFile} ${dataFile}.old X mv ${dataFile}.tmp ${dataFile} Xfi X Xunlockfile ${dataFile}.lock || { echo "${test}: my lock file has been broken!" 1>&2; exit 11; } END_OF_FILE if test 1873 -ne `wc -c <'netwatch/bin/netwatch.servers'`; then echo shar: \"'netwatch/bin/netwatch.servers'\" unpacked with wrong size! fi chmod +x 'netwatch/bin/netwatch.servers' # end of 'netwatch/bin/netwatch.servers' fi if test -f 'netwatch/bin/timeout.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'netwatch/bin/timeout.c'\" else echo shar: Extracting \"'netwatch/bin/timeout.c'\" \(996 characters\) sed "s/^X//" >'netwatch/bin/timeout.c' <<'END_OF_FILE' X/* X * NetWatch 1.0 X * (c) Copyright 1996 by Johnson Earls (darkfox@netcom.com) X * X * timeout -- run a program, with a timeout X * X * usage: X * timeout