head 1.12; access; symbols; locks alexis:1.12; strict; comment @# @; 1.12 date 95.11.03.00.14.33; author alexis; state Exp; branches; next 1.11; 1.11 date 95.10.31.12.15.55; author alexis; state Exp; branches; next 1.10; 1.10 date 95.10.29.17.52.55; author alexis; state Exp; branches; next 1.9; 1.9 date 95.10.28.14.48.52; author alexis; state Exp; branches; next 1.8; 1.8 date 95.10.27.13.35.44; author alexis; state Exp; branches; next 1.7; 1.7 date 95.10.15.22.08.57; author alexis; state Exp; branches; next 1.6; 1.6 date 95.10.15.22.07.51; author alexis; state Exp; branches; next 1.5; 1.5 date 95.10.15.22.06.14; author alexis; state Exp; branches; next 1.4; 1.4 date 95.10.15.20.41.08; author alexis; state Exp; branches; next 1.3; 1.3 date 95.10.14.17.17.16; author alexis; state Exp; branches; next 1.2; 1.2 date 95.10.14.17.14.34; author alexis; state Exp; branches; next 1.1; 1.1 date 95.10.14.16.26.01; author alexis; state Exp; branches; next ; desc @S Y S T E M I N F O A small program to report a lot of things on a daily basis. @ 1.12 log @More graceful handling of failure to call 'incp -V'. Missing syslog, xferlog, incplog are not errors. @ text @#!/bin/sh PROGNAME=`basename $0` VERSION='$Id: si,v 1.11 1995/10/31 12:15:55 alexis Exp alexis $' DFLT_SI_ZERO=false DFLT_SI_MODE=cat DFLT_SI_RECP=root DFLT_SI_INTV_ON=false DFLT_SI_INTV=7 DEBUG_LEVEL=2 MESSAGES=/var/adm/messages XFERLOG=/var/adm/xferlog INCPLOG=/var/adm/incplog HN=`hostname` FQHN=`hostname -f` VERSION=`echo $VERSION | cut -d' ' -f3` MAILX=/bin/mailx INCP=/usr/local/lib/ppp/incp FLAG_DIR=/var/local/lib FLAG_FILE=$FLAG_DIR/$PROGNAME.dlr debug() { [ $DEBUG_LEVEL -ge $1 ] && echo "$PROGNAME: DEBUG[$1]: $2" } intro() { echo echo "****************** SYSTEM INFORMATION REPORT ********************" echo { echo "HOST: $FQHN" echo "DATE: `date`" } | tr '[a-z]' '[A-Z]' echo GENERATED WITH: $PROGNAME $VERSION echo } disk_usage() { echo "DISK USAGE" echo "----------" echo df echo } bad_logins() { # Oct 13 16:36:05 danae login: 1 LOGIN FAILURE ON tty3, root echo "LOGIN FAILURES" echo "--------------" echo if [ -r $MESSAGES ]; then cat $MESSAGES | sed -n "s/^\(...\) \(..\) \(..:..:..\) $HN login: [0-9][0-9]* LOGIN FAILURE ON \(.*\), \(.*\)$/\1 \2 \3 \4 \5/p" \ | awk '{ printf "%s %02d %s %-5s %s\n", $1, $2, $3, $4, $5}' if [ $SI_ZERO = true ]; then cp $MESSAGES $MESSAGES.old > $MESSAGES fi fi echo } ftp_transfers() { echo "FTP TRANSFERS" echo "-------------" echo if [ -r $XFERLOG ]; then cat $XFERLOG | sed -n -e 's/^... \(... .. ..:..:..\) 199. [0-9][0-9]* \([^ ][^ ]*\) [0-9][0-9]* \([^ ][^ ]*\) . . i .*/\1 \2 put \3/p' \ -e 's/^... \(... .. ..:..:..\) 199. [0-9][0-9]* \([^ ][^ ]*\) [0-9][0-9]* \([^ ][^ ]*\) . . o .*/\1 \2 get \3/p' if [ $SI_ZERO = true ]; then cp $XFERLOG $XFERLOG.old > $XFERLOG fi fi echo } error() { echo "$PROGNAME: ERROR: $1" exit 1 } warning() { echo "$PROGNAME: WARNING: $1" } in_connections() { echo "INTERNET CONNECTIONS" echo "--------------------" echo if [ ! -x $INCP ]; then warning "can't find internet connection program" elif ! INCP_VERSION=`$INCP -V 2>/dev/null`; then warning "couldn't get internet connection program version number" elif [ "$INCP_VERSION" != "incp version 1.8" ]; then warning "$PROGNAME version $VERSION is not compatible with $INCP_VERSION" elif [ -r $INCPLOG ]; then cat $INCPLOG | sed -n -e "s/^\(... .. ..:..:..\) $HN incp\[.*\]: \(CONNECTED.*\)$/\1 \2/p" \ -e "s/^\(... .. ..:..:..\) $HN incp\[.*\]: \(DISCONNECTED.*\)$/\1 \2/p" if [ $SI_ZERO = true ]; then cp $INCPLOG $INCPLOG.old > $INCPLOG fi fi echo } in_mail_check() { echo "USERS WITH UNREAD MAIL" echo "----------------------" echo for FILE in /var/spool/mail/*; do if egrep '^Status: O$|^Status: N$' $FILE > /dev/null; then ls -ld --full-time $FILE | sed 's/^.......... *[1-9][1-9]* *[^ ][^ ]* *[^ ][^ ]* *[0-9][0-9]* ... \(... .. ..:..:..\) 199. \/var\/spool\/mail\/\(.*\)$/\1 \2/' fi done echo } out_mail_check() { echo "UNDELIVERED OUTBOUND MAIL" echo "-------------------------" echo mailq echo } log_file_sizes() { echo "LARGE LOG FILES" echo "---------------" echo for FILE in /var/adm/*; do if [ -f $FILE ]; then SIZE=`du $FILE | cut -f1 -d' '` [ $SIZE -gt 300 ] && ls -ld --full-time $FILE | sed "s/^.......... *[1-9][1-9]* *[^ ][^ ]* *[^ ][^ ]* *[0-9][0-9]* ... \(... .. ..:..:..\) 199. \(\/var\/adm\/.*\)$/\1 \2 $SIZE/" fi done | awk '{ printf "%s %s %s %-25s %4dKb\n", $1, $2, $3, $4, $5}' echo } usage() { echo "Usage: $PROGNAME [ -d debuglevel ] [ -m [ user ... ] ] [ -z ] [ -daycount ]" echo " $PROGNAME -V" exit 1 } gen_report() { intro disk_usage bad_logins ftp_transfers in_connections in_mail_check out_mail_check log_file_sizes } main() { SI_MODE=$DFLT_SI_MODE SI_ZERO=$DFLT_SI_ZERO SI_RECP=$DFLT_SI_RECP SI_INTV=$DFLT_SI_INTV SI_INTV_ON=$DFLT_SI_INTV_ON while [ "X$1" != X ]; do case "$1" in -d) [ "X$2" = X ] && usage DEBUG_LEVEL=$2 shift ;; -m) SI_MODE=mail while expr "$2" : "^[^\-].*" > /dev/null; do SI_RECP="$SI_RECP $2" shift done [ "X$SI_RECP" = X ] && SI_RECP=$DFLT_SI_RECP ;; -z) SI_ZERO=true ;; -V) echo "$PROGNAME version $VERSION" exit ;; -[0-9]*) debug 5 "Changing SI_INTV_ON" SI_INTV_ON=true SI_INTV=`expr "$1" : "^-\([0-9][0-9]*\)"` ;; -*) usage ;; *) break ;; esac shift done debug 5 "MODE=$SI_MODE, SI_INTV_ON=$SI_INTV_ON" # check that we can run at this time if [ $SI_INTV_ON = true ]; then [ `id | sed 's/^uid=\([0-9][0-9]*\)(.*/\1/'` -eq 0 ] || error "you must be root to use the '-num' option" [ -d $FLAG_DIR ] || error "can't access directory '$FLAG_DIR'" DAY_THIS_RUN=`date '+%j'` [ -f $FLAG_FILE ] || echo "-99999" > $FLAG_FILE read DAY_LAST_RUN < $FLAG_FILE expr "$DAY_LAST_RUN" : "^[-]?[0-9][0-9]*$" > /dev/null || error "invalid day number in $FLAG_FILE'" [ $DAY_LAST_RUN -gt $DAY_THIS_RUN ] && DAY_LAST_RUN=`expr $DAY_LAST_RUN - 365` [ `expr $DAY_THIS_RUN - $DAY_LAST_RUN` -lt $SI_INTV ] && { debug 5 "exiting because run already today" exit 0 } fi if [ $SI_MODE = cat ]; then gen_report else gen_report | $MAILX -s "System Information" $SI_RECP fi if [ $SI_INTV_ON = true ]; then echo "$DAY_THIS_RUN" > $FLAG_FILE fi } main "$@@" @ 1.11 log @Corrected rescheduling code. Now uses flag file under /var/local/lib. Added debug support. @ text @d3 1 a3 1 VERSION='$Id: si,v 1.10 1995/10/29 17:52:55 alexis Exp alexis $' a65 2 else warning "can't open $MESSAGES" a81 2 else warning "can't open $XFERLOG" a98 3 # Oct 14 15:40:12 danae incp[1017]: Connected - acce INCP_VERSION=`$INCP -V` d103 7 a109 1 if [ "$INCP_VERSION" != "incp version 1.8" ]; then d112 1 a112 4 elif [ ! -r $INCPLOG ]; then warning "can't open $INCPLOG" else @ 1.10 log @Moved the code that checks if the user is root to after the "-V" option processing in order to allow non-root users to do "si -V". @ text @d3 9 a11 1 VERSION='$Id: si,v 1.9 1995/10/28 14:48:52 alexis Exp alexis $' a18 2 FLAG_FILE=/tmp/$PROGNAME.lr SI=~alexis/dev/si/si d22 7 d92 1 a92 1 echo "ERROR: $1" d98 1 a98 1 echo "WARNING: $1" a129 2 # -rw-r--r-- 1 root root 67 Sun Oct 15 18:25:46 1995 x # -rw-rw---- 1 alexis mail 1677 Sun Oct 15 20:25:14 1995 /var/spool/mail/alexis d166 2 a167 1 echo "Usage: $PROGNAME [ -m [ user ... ] ] [ -z ] [ -a HHMM ]" d185 5 a189 15 DFLT_SI_MODE=cat DFLT_SI_ZERO=false DFLT_SI_TIME="" DFLT_SI_RECP=root [ "$SI_MODE" ] || SI_MODE=$DFLT_SI_MODE [ "$SI_ZERO" ] || SI_ZERO=$DFLT_SI_ZERO THIS_RUN=`date '+%j'` if [ "$SI_TIME" -a -f $FLAG_FILE ]; then LAST_RUN=`cat $FLAG_FILE` [ $LAST_RUN -eq $THIS_RUN ] && warning "possibly more than one scheduled system info report" else SI_TIME=$DFLT_SI_TIME fi d193 23 a215 15 -m) SI_MODE=mail while expr "$2" : "^[^\-].*" > /dev/null; do SI_RECP="$SI_RECP $2" shift done [ "X$SI_RECP" = X ] && SI_RECP=$DFLT_SI_RECP ;; -z) SI_ZERO=true ;; -V) echo "$PROGNAME version $VERSION" exit ;; -a) [ "X$2" = X ] && usage SI_TIME="$2" SI_MODE=mail shift ;; -*) usage ;; *) break ;; d220 1 a220 2 [ `id | sed 's/^uid=\([0-9][0-9]*\)(.*/\1/'` -eq 0 ] || error "you must be root to run this program" export SI_MODE SI_ZERO SI_TIME SI_RECP d222 15 d243 2 a244 3 if [ "$SI_TIME" ]; then echo $SI | at $SI_TIME > /dev/null 2>&1 echo $THIS_RUN > $FLAG_FILE @ 1.9 log @Addition of a function to report on outbound mail queue. @ text @d3 1 a3 1 VERSION='$Id: si,v 1.8 1995/10/27 13:35:44 alexis Exp alexis $' a172 1 [ `id | sed 's/^uid=\([0-9][0-9]*\)(.*/\1/'` -eq 0 ] || error "you must be root to run this program" d210 1 @ 1.8 log @Incp section now checks version of incp before examining or removing logs. Zeroing of logs is now done in the section pertaining to that log rather than at the end of the program. @ text @d3 1 a3 1 VERSION='$Id: si,v 1.7 1995/10/15 22:08:57 alexis Exp alexis $' d115 1 a115 1 mail_check() d130 9 d166 2 a167 1 mail_check @ 1.7 log @Same problem. @ text @d3 1 a3 1 VERSION='$Id$' a7 1 SYSLOG=/var/adm/syslog d15 1 d49 4 d67 4 d79 1 a79 1 echo "$PROGNAME: ERROR: $1" d85 1 a85 1 echo "$PROGNAME: WARNING: $1" d91 1 d96 8 a103 1 if [ -r $INCPLOG ]; then d106 5 a111 3 else warning "can't open $INCPLOG" fi a206 11 fi if [ $SI_ZERO = true ]; then cp $SYSLOG $SYSLOG.old > $SYSLOG cp $XFERLOG $XFERLOG.old > $XFERLOG cp $MESSAGES $MESSAGES.old > $MESSAGES cp $INCPLOG $INCPLOG.old > $INCPLOG @ 1.6 log @RCS version id line got corrupted and wasn't being bumped. @ text @d3 1 a3 1 VERSION='$Id' @ 1.5 log @Added full path to mailx command so that root can run the script with being told that he can't run mailx. @ text @d3 1 a3 1 VERSION='$Id: si,v 1.3 1995/10/14 17:17:16 alexis Exp root ' @ 1.4 log @Massive revisions. Support for options and for putting in atq. Lots of changes. @ text @d15 1 d188 1 a188 1 gen_report | mailx -s "System Information" $SI_RECP @ 1.3 log @Syntax error got in. @ text @d3 1 a3 1 # $Id: si,v 1.2 1995/10/14 17:14:34 alexis Exp alexis $ d5 2 a6 2 MESSAGELOG=/var/adm/messages FTPXFERLOG=/var/adm/xferlog d8 1 d12 3 d19 7 a25 2 echo " *** SYSTEM INFORMATION REPORT ***" echo " *** $FQHN *** `date` ***" | tr '[a-z]' '[A-Z]' d40 2 d45 3 a47 4 if [ -r $MESSAGELOG ]; then sed -n "s/^\(.*\) $HN login: \(.*\) LOGIN FAILURE ON \(.*\), \(.*\)$/\1 \2 \3 \4/p" \ $MESSAGELOG 2>&1 \ | awk '{ printf "%s %2d %s (%02d) %-5s %s\n", $1, $2, $3, $4, $5, $6}' d49 1 a49 1 warning "can't open $MESSAGELOG" d59 3 a61 2 if [ -r $FTPXFERLOG ]; then cat $FTPXFERLOG 2>&1 d63 1 a63 1 warning "can't open $FTPXFERLOG" d68 6 d81 2 d87 3 a89 1 sed 's/^\([^ ][^ ]* [^ ][^ ]* [^ ][^ ]*\) [^ ][^ ]* [^ ][^ ]* \(.*\)$/\1 \2/' < $INCPLOG d98 2 d104 3 a106 1 [ -s $FILE ] && ls -ld $FILE | sed 's/^[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *\([^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]*\) \/var\/spool\/mail\/\([^ ][^ ]*\)/\1 \2/' d119 1 a119 1 [ $SIZE -gt 300 ] && echo $FILE: ${SIZE}Kb d121 1 a121 1 done d127 1 a127 1 echo "Usage: $PROGNAME [ -m ]" d144 17 a160 1 MODE=cat d163 13 a175 1 -m) MODE=mail ;; d182 23 a204 4 case $MODE in cat) gen_report ;; mail) gen_report | mail -s "System Info" root ;; esac @ 1.2 log @Lots of changes. Now works (did before) but still has a lot of changes to go. @ text @d3 1 a3 1 # $Id$ d37 1 a37 1 | awk '{ printf "%s %2d %s (%02d) %-5s %s\n", $1, $2, $3, $4, $5, $6}' \ @ 1.1 log @Initial revision @ text @d2 2 d5 3 a7 2 MESSAGE_LOG="/var/adm/messages" TRANSFER_LOG="/var/adm/xferlog" d15 1 a15 1 echo " *** SYSTEM INFORMATION REPORT ***" d29 1 a29 1 last_logged_in() d34 7 a40 4 sed -n "s/^\(.*\) $HN login: \(.*\) LOGIN FAILURE ON \(.*\), \(.*\)$/\1 \2 \3 \4/p" \ $MESSAGE_LOG \ | awk '{ printf "%s %2d %s (%02d) %-5s %s\n", $1, $2, $3, $4, $5, $6}' # Oct 6 09:57:38 danae login: 1 LOGIN FAILURE ON tty3, alexis d49 5 a53 1 cat $TRANSFER_LOG d57 5 d67 5 a71 1 sed -n "s/^\(.*\) $HN incp\[[0-9]*\]: \(.*\)/\1 \2/p" $MESSAGE_LOG d77 2 a78 2 echo "UNREAD MAIL" echo "-----------" d81 1 a81 1 [ -s $FILE ] && ls -ld $FILE d86 1 a86 1 check_log_file_sizes() d94 1 a94 1 [ $SIZE -gt 30 ] && echo $FILE: ${SIZE}Kb d100 36 a135 7 intro disk_usage last_logged_in # ftp_transfers # in_connections mail_check check_log_file_sizes @