#!/usr/bin/perl $PIDFILE = "/var/run/nfs-remove-monitor.pid"; $LOGFILE_BASE = "/var/log/nfs-remove-monitor"; $EXIT = 0; $SIG{CHLD} = IGNORE; if ( -e $PIDFILE ) { $PID = `cat $PIDFILE`; `kill -HUP $PID`; $DATE=`date +%F`; chomp $DATE; unlink "$LOGFILE_BASE.$DATE.log"; unlink "$LOGFILE_BASE.$DATE.log.bz2"; rename "$LOGFILE_BASE.log", "$LOGFILE_BASE.$DATE.log"; unless (fork()) { sleep 5; `bzip2 -9 $LOGFILE_BASE.$DATE.log`; exit; } } open PID, ">$PIDFILE"; print PID $$; close PID; open LOG, ">$LOGFILE_BASE.log"; $STDOUT = select LOG; $|=1; select $STDOUT; open TCPDUMP, "tcpdump -vvvvvv -l -i any -s 0 tcp 2>/dev/null |"; $STDOUT = select TCPDUMP; $|=1; select $STDOUT; $SIG{HUP} = sub { $EXIT = 1; }; while ($line =) { if ($line =~ /remove/) { print LOG $line; } last if $EXIT; } close TCPDUMP; close LOG;
don't forget to rotate your logs...
No comments:
Post a Comment