#!/bin/csh -f # # Monty - Monthly local accounting and log management # # This script starts fresh system logs, using the newlog script. # It is intended to be run about once a month. Old copies of the # logs are kept for several months, just in case they are needed. # You can specify how many back copies to keep in the newlog command. # # Eric Myers University of Michigan Physics Department # @(#) $Id: Monty,v 2.12 2008/10/01 14:29:46 myers Exp myers $ ####################################################################### # Set the path just to what is needed for newlog, webcount, # or other commands, nothing else. set path=( /usr/local/adm /usr/local/bin /usr/local/sbin ) set path=( $path /sbin /usr/sbin /bin /usr/bin /usr/etc ) ## INITD is path to init.d scripts set INITD=/etc/rc.d/init.d ## Where to print the administration logs for off-line storage ## Make sure this is a secure printer - the logs contain sensitive info. ## Logs are not printed if this is not set. ### set LPR="lpr" # how to print logs ## # MAILX is mail/mailx or mush, with -s flag for setting subject. # It's used for mailing statistics from webcount and xfercount to root. set MAILX="mail -s" # NeXT/Linux/Sun if ( -x /usr/bin/mailx ) then # HP-UX is in /usr/bin set MAILX="mailx -s " endif if ( -x /usr/local/bin/mush ) then # mush is prefered set MAILX="mush -s " endif set RCSVERS = \ `echo '$Revision: 2.12 $' | sed -e 's/Revision: //' -e 's/$\(.*\) \$/\1/'` set HOSTNAME = `hostname` set INDENT="pr -o 8 -t " ######### umask 037 set TMP=/tmp/Monty.$$-1 set LOG=/tmp/Monty.out /bin/rm -f ${LOG} ################################# ## @(#)* Start new wtmp file (which records login/logout) # First you have to find where it is... set WTMPS=( /usr/adm/wtmp /etc/wtmp /var/adm/wtmp /var/log/wtmp ) foreach FILE ( $WTMPS ) if ( -f $FILE ) newlog $FILE 4 644 end # HP-UX 10.x also saves failed logins in /var/adm/btmp if ( -f /var/adm/btmp ) newlog /var/adm/btmp 4 644 ######################### ## @(#)* Start new system log(s) # # These are all possible system logs. set SYSLOGS=( /var/adm/syslog/syslog.log /usr/adm/messages \ /var/log/messages /var/log/syslog ) foreach FILE ( $SYSLOGS ) if ( -f $FILE ) newlog $FILE 6 644 end ######################### ## @(#)* Start new mail log(s) # # These are all possible mail log files. Start a new one if one # already exists and is not empty. set MAILLOGS=( /usr/spool/mqueue/syslog /var/log/mail.log /usr/adm/mail.log ) set MAILLOGS=( $MAILLOGS /var/adm/syslog/mail.log /var/log/maillog ) foreach FILE ( $MAILLOGS ) if ( -f $FILE && -s $FILE ) newlog $FILE 4 640 end ######################### ## @(#)* Start new authorization/security log(s) # # These are all possible authorization/security logs. # Start a new one if one already exists and is not empty. set AUTHLOGS=( /usr/adm/sulog /var/adm/syslog/authlog.log /var/adm/authlog ) set AUTHLOGS=( $AUTHLOGS /var/log/auth.log /usr/adm/auth.log /var/log/secure ) foreach FILE ( $AUTHLOGS ) if ( -f $FILE && -s $FILE ) newlog $FILE 6 640 end #################### ## @(#)* Start new debug logs set DEBUGLOGS=( /var/adm/syslog/debug /var/log/debug ) foreach FILE ( $DEBUGLOGS ) if ( -f $FILE && -s $FILE ) newlog $FILE 5 end #################### ## @(#)* Start new crond logs set CRONLOGS=( /var/log/cron /var/adm/cron/log ) foreach FILE ( $CRONLOGS ) if ( -f $FILE ) newlog $FILE 3 end #################### ## @(#)* New root history logs set LOGS=( /root/.bash_history /root/.history ) foreach FILE ( $LOGS ) if ( -f $FILE ) newlog $FILE 3 end #################### ## @(#)* Start new X logs set LOGS=( /var/log/xdm-errors.log /var/log/xdm-errors ) foreach FILE ( $LOGS ) if ( -f $FILE ) newlog $FILE 3 end #################### ## @(#)* Start new accounting logs set LOGS=( /var/log/pacct ) foreach FILE ( $LOGS ) if ( -f $FILE ) newlog $FILE 3 end ################################ ## @(#)* Start new printer log/accounting files # Match the names of the log/accounting files # to the names given in /etc/printcap # BSD: SunOS 4.1.3 at Vassar / NeXTs at U-M / Solaris at TFR: if ( -d /usr/spool/lpd ) then cd /usr/spool/lpd foreach PRINTER ( `ls -1` ) if ( -d /usr/spool/lpd/${PRINTER} ) then cd /usr/spool/lpd/${PRINTER} if ( -f log ) mv log ${PRINTER}.log if ( -f acct ) mv acct ${PRINTER}.acct if ( -f ${PRINTER}.log ) newlog ${PRINTER}.log 3 664 if ( -f ${PRINTER}.acct ) newlog ${PRINTER}.acct 3 664 endif end endif if ( -f /usr/adm/lpd-errs ) newlog /usr/adm/lpd-errs 3 644 if ( -f /usr/local/adm/lpd-errs ) newlog /usr/local/adm/lpd-errs 3 644 # HP-UX 9.X: if ( -f /usr/spool/lp/lpd.log ) newlog /usr/spool/lp/lpd.log 3 644 # HP-UX 10.xx @physics.lsa.umich.edu if ( -f /var/adm/lp/log ) newlog /var/adm/lp/log 6 644 if ( -f /var/adm/lp/acct ) newlog /var/adm/lp/acct 6 644 #################### ## @(#)* Start new DUMPDATE logs for backups set DUMPDIR=/usr/local/adm/dumpdir if ( -d $DUMPDIR ) then cd $DUMPDIR if ( -f ./DUMPDATE ) newlog DUMPDATE 12 endif #################### ## @(#)* Start new ppp logs set PPPDIR=/etc/ppp set FILE=connect-errors if ( -d $PPPDIR ) then cd $PPPDIR if ( -f $FILE ) newlog $FILE 2 endif #################### ## @(#)* Generate web server usage report(s) and rotate logs set WEBLOGDIRS=( /var/log/httpd /usr/local/etc/httpd/logs /usr/local/apache/logs ) cp /dev/null $TMP foreach LOGDIR ( $WEBLOGDIRS ) if ( ! -d $LOGDIR ) continue cd $LOGDIR # Generate usage report if a log file exists if ( -f $LOGDIR/access_log ) then webcount /html/ -f $LOGDIR/access_log >> $TMP echo " " >>$TMP endif if ( ! -z $TMP ) then cat <>$LOG ### Monthly httpd summary for $HOSTNAME from $LOGDIR/access_log EOT cat $TMP >>$LOG endif ## @(#)* Start new web server logs if ( -f access_log && -s access_log ) newlog access_log 12 644 if ( -f error_log && -s error_log ) newlog error_log 6 644 if ( -f referer_log && -s referer_log ) newlog referer_log 6 644 if ( -f agent_log && -s agent_log ) newlog agent_log 6 644 if ( -f suexec_log && -s suexec_log ) newlog suexec_log 6 644 # Must HUP the daemon after change of log files, so try various ways # to get the process ID (PID). Last one to succeed is the one we use. set PSPROC="ps -aux" if ( `uname` == "Linux") set PSPROC="ps aux" if ( `uname` == "HP-UX") set PSPROC="ps -ef " set HTTPPID=`$PSPROC | grep http | grep -v grep | awk '$1 ~ /^root$/ {print $2}' ` if ( -f ./httpd.pid ) set HTTPPID = `cat ./httpd.pid` if ( -f ./httpsd.pid ) set HTTPPID = `cat ./httpsd.pid` if ( -f /var/run/httpd.pid ) set HTTPPID=`cat /var/run/httpd.pid` if ( "$HTTPPID" != "" ) kill -HUP $HTTPPID end ############################## ## @(#)* Start new administrative logs using Pamela ## [These should be printed and saved offline in case of disk crash] set ADMINLOG=/usr/local/adm/adminlog if ( -f /var/adm/adminlog ) set ADMINLOG=/var/adm/adminlog # Alternate if ( -f $ADMINLOG ) then if ( $?LPR ) then Pamela $ADMINLOG | $LPR endif newlog $ADMINLOG 12 endif #################### ## @(#)* New SQL server logs # # (needs more work to be more general - this is RH Linux 7.x/MySQL 3.23.56 set SQLPID="" set PIDFILE=/var/lib/mysqld/${HOSTNAME}.pid if ( -f "$PIDFILE" ) set SQLPID=`cat $PIDFILE` if ( "$SQLPID" != "" ) service mysqld stop ## New log files: set SQLLOGDIRS=( /var/lib/mysql /var/log ) foreach LOGDIR ( $SQLLOGDIRS ) if ( -d $LOGDIR ) then cd $LOGDIR set ERRFILE=${HOSTNAME}.err if ( -f $ERRFILE && -s $ERRFILE ) newlog $ERRFILE 12 644 endif end # If it was running start it again if ( "$SQLPID" != "" ) service mysqld start ############################## ## @(#)* Generate ftp server usage reports, start new ftp server logs set FTPLOGS=( /var/log/xferlog /usr/adm/xferlog ) set XFERCOUNT="/usr/local/adm/xfercount" foreach FILE ( $FTPLOGS ) if ( -f $FILE && ! -z $FILE ) then cat <>$LOG ### Monthly ftp summary for $HOSTNAME from $FILE EOT xferstats -f $FILE -s ~ftp/pub -l 7 >>$LOG if ( -x "$XFERCOUNT" ) then echo " " >>$LOG xfercount -f $FILE >>$LOG echo " " >>$LOG endif newlog $FILE 6 664 endif end ############################## ## @(#)* New arpwatch log if ( -d /var/arpwatch && ! -z /var/arpwatch/arp.dat ) then set N=`/usr/bin/wc -l 0 ) then cat <>$LOG ### Arpwatch count There are ${N} records in /var/arpwatch/arp.dat The arpwatch daemon is being reset. EOT # Stop for new log, then start again if ( -x ${INITD}/arpwatch ) then ${INITD}/arpwatch stop newlog /var/arpwatch/arp.dat ${INITD}/arpwatch start endif endif endif #################### ## @(#)* Start new iperf logs set IPERFLOGS=( /var/log/iperf.log /var/log/iperf-daemon.log ) foreach FILE ( $IPERFLOGS ) if ( -f $FILE ) newlog $FILE 12 end ############### ## @(#)* HUP syslogd to be sure new syslog/maillog files are used set SPID="" if ( -f /etc/syslog.pid ) set SPID=`cat /etc/syslog.pid` if ( -f /var/run/syslogd.pid ) set SPID=`cat /var/run/syslogd.pid` if ( -f /var/run/rsyslogd.pid ) set SPID=`cat /var/run/rsyslogd.pid` if ( "$SPID" != "") kill -HUP $SPID # On an HP an external console will reset back to 300 baud unless... if ( -e /dev/tty0p0 ) then sleep 1 stty 38400 &/dev/null /bin/rm -f ${TMP} >&/dev/null exit