in reply to Re: Re: Diagnositc output on background processes
in thread Diagnositc output on background processes

Well, you could always create a separate diagnostics log file and use a different "monitor" script that simply monitors the size of the diagnostics file and then tails/echoes any new lines when detected to the screen.

I have a script that does this for my backup job stream. When the backup job kicks off it appends whatever is in the daily log file, to the cumulative log file, deletes the daily log, kicks off the monitor job to run in the background and appends any new output to the daily log file. The monitor job echoes everything that is appended to the daily log file to the screen. It even repeats the last line periodically so that the operators can see if something is hung or not. In my case though, the monitor job only runs as long as its parent job is running. But if the terminal session hangs/dies/whatever the log file still has all the diagnostics.

If you like, I could post both backup and monitor scripts, so you could see how they interact.

If the code and the comments disagree, then both are probably wrong. -- Norm Schryer

  • Comment on Re: Re: Re: Diagnositc output on background processes

Replies are listed 'Best First'.
Re: Re: Re: Re: Diagnositc output on background processes
by gomez18 (Sexton) on Aug 25, 2001 at 01:55 UTC
    That sounds perfect. If you get a chance to post the code, that would be immensely helpful. Thanks again to everyone for all your help.

    An 8 bit man in a 32 bit world.

      BTW, the backup script is a cshell script but it is easy to tell what is going on. Apologies on the Perl script, it was written in 1997, before I knew about use strict.

      daily cshell backup script

      #! /bin/csh -f # This script file backs up /www and /export directories # clear set log = '/export/home/operator/daily.log' set oldlog = '/export/home/operator/daily.old.log' set problem = 0 set linect = 0 if (-e $log) then cat $log >> $oldlog rm $log endif # invoke Perl monitor job to run in background /export/home/operator/bkup.monitor $log $linect & echo "** ################################################### **" >> $l +og echo "** ATTENTION OPERATOR ** Please insert the Backup tape **" >> $l +og echo " " >> $log echo -n " After tape drive light becomes steady, press the return ke +y" >> $log echo " " >> $log set var=($<) if ($?var == 1) unset var echo "** Backup begins ("`date '+%y/%m/%d %H:%M'`") **" >> $log echo " " >> $log echo " Backing up -> /www" >> $log echo " " >> $log ufsdump 0uf /dev/rmt/0n /www >> & $log echo " " >> $log set rc = $status if ($rc != 0) then echo "--Error backing up /www " >> $log set problem = `expr $problem + 1` endif echo " Backing up -> /export" >> $log echo " " >> $log ufsdump 0uf /dev/rmt/0n /export >> & $log echo " " >> $log set rc = $status if ($rc != 0) then echo "--Error backing up /export " >> $log set problem = `expr $problem + 1` endif echo " Backing up -> /www2/export" >> $log echo " " >> $log ufsdump 0uf /dev/rmt/0n /www2 >> & $log echo " " >> $log set rc = $status if ($rc != 0) then echo "--Error backing up /www2 " >> $log set problem = `expr $problem + 1` endif if ($problem != 0) then echo "** $problem PROBLEMS ENCOUNTERED DURING BACKUP **" >> $log echo " " >> $log echo " " >> $log goto done endif echo "** BACKUP COMPLETED SUCCESSFULLY **" >> $log echo " " >> $log echo " " >> $log /export/home/operator/daily.listings "$log" done: echo "** JOB ENDED "`date '+%y/%m/%d %H:%M'`" **" >> $log echo " " >> $log echo "** REWINDING & UNLOADING TAPE. PLEASE WAIT . . ." >> $log mt -f /dev/rmt/0 rewoffl echo " " >> $log exit -1

      bkup.monitor Perl script

      #!/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"; }

      Update: Took out BLOCKQUOTE tags around code.

      If the code and the comments disagree, then both are probably wrong. -- Norm Schryer