#!/bin/csh # netlogchop script # pulls network hardware logs and mails to root # should be run as a cron job at 1159pm # version 1.1 # version history # 1.0: first public release 10/27/03 # 1.1: oops fix 11/2/03 # grab target date and wait until just after midnight set date = `/bin/date "+%b %e"` set month = `/bin/date +%b` @ day = `/bin/date +%e` set year = `/bin/date +%Y` /bin/sleep 120 # loop on filename / description foreach device (router switch firewall) # initialize temporary logfile but make sure it's not empty /bin/cp /dev/null /var/log/$device.daily echo "" > /var/log/$device.daily # check last rolled-over logfile if (-e /var/log/$device.0.gz && $day >= 10) \ /usr/bin/gunzip -c /var/log/$device.0.gz | \ /usr/bin/grep -w "^$date" >>& /var/log/$device.daily if (-e /var/log/$device.0.gz && $day < 10) \ /usr/bin/gunzip -c /var/log/$device.0.gz | \ /usr/bin/grep -w "^$month $day" >>& /var/log/$device.daily # check tonight's logfile if (-e /var/log/$device && $day >= 10) \ /usr/bin/grep -w "^$date" /var/log/$device >>& /var/log/$device.daily if (-e /var/log/$device && $day < 10) \ /usr/bin/grep -w "^$month $day" /var/log/$device >>& /var/log/$device.daily # additional filters # mail to root /bin/cat /var/log/$device.daily | \ /usr/bin/mail -s "$device log $month $day $year output" root # end loop end