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


In reply to Re: Re: Re: Re: Re: Diagnositc output on background processes by jlongino
in thread Diagnositc output on background processes by gomez18

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.