#!/usr/bin/perl use English; ## name of log file is passed by the backup script, get PID of backup (parent) script $ppid = getppid; ## print "\$ppid: $ppid\n\n"; $logfile = @ARGV[0]; $lastlc = @ARGV[1]; ## print "\$lastlc: $lastlc\n\n"; ## look to see if backup job is still running ## run while backup job is still running while (getppid == $ppid) { ## how many lines are currently in the $logfile? $wc = `wc $logfile`; @awc = split " ", $wc; $linect = $awc[0]; ## are there are more lines than the last time we checked? if ($linect > $lastlc) { ## display the new lines in the log file. &ShowLog ($linect, $lastlc); $lastlc = $linect; } ## I want to sleep for 5 seconds, you can make this shorter if you like. ## I don't recommend not sleeping though, since it will chew up CPU cycles sleep 5; } ## backup job is no longer running ## check to see if any new lines have been added $wc = `wc $logfile`; @awc = split " ", $wc; $linect = $awc[0]; if ($linect > $lastlc) { ## display new log file lines &ShowLog ($linect, $lastlc); $lastlc = $linect; } exit; sub ShowLog { my ($linect, $lastlc) = @ARG; ## determine how many lines have been added $showlines = $linect - $lastlc; ## use tail command to display newly appended lines ## print "$showlines = $linect - $lastlc\n\n"; system "tail -$showlines $logfile"; }