#! /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 |