> >if [ -f /tmp/backup/lockdir/pid ] ; then
> > OLDPID=$( cat /tmp/backup/lockdir/pid )
> > if ! ps -ef \
> > | awk '{print $2}' \
> > | grep $OLDPID > /dev/null 2>&1; then
> > echo "Backup $OLDPID hasn't completet and isn't running">>$ERR
> > rm /tmp/backup/lockdir/pid
> > rmdir /tmp/backup/lockdir
> > fi
> >fi
> checking PID is better than checking lockdir alone. much better. But there
> still a good chance that the PID is used by other programs and that you
> think a duplicate copy is running. I think checking PID and the program
> name will significantly reduce this type of error. Thanks for the idea.
And another one:
If $OLDPID exists and the old script is running which can be easily checked,
then it's a good idea to test weather it works fine ore something goes
wrong. If your script produces network traffic, you could test this with the
snoop command (since this posting goes also to comp.unix.solaris, I'd guess
you use it und thus have snoop).
Here's a code which does this (Thx to I. Sparry, who gave me the hint how
to do this :-). In my case the problem was, that if the backupprocess on
the client hangs or the client goes down during the backup, the program
on the backuphost just waited for data all the time since there is no
timeout spcified ...
The following code runs within the Backupscript:
startbackupjob &
BACKUP_PID=$!
sleep 60
if ps -p $BACKUP_PID > /dev/null 2>&1
then
while testthebackup $HOST $BACKUP_PID >> /dev/null 2 >&1
do
sleep 600
if ! ps -p $BACKUP_PID > /dev/null 2>&1
then
break
fi
done
fi
if ps -p $BACKUP_PID > /dev/null 2>&1
then
if [ rsh $HOST ls > /dev/null 2>&1 ]; then
rsh $HOST ps -ef | grep backupclient | einszeil $HOST >> $ERR
fi
kill -9 $BACKUP_PID >> $ERR 2>&1
fi
(einszeil $HOST just inserts $HOST at the beginning of each line of input)
And testthebackup is:
#!/bin/sh
HOST=$1
BACKUP_PID=$2
trap 'exit 1' 8
(sleep 600 ; kill -8 $$ ) &
SLEEP_PID=$!
if [ ! $HOST = $BACKUP ]
then
snoop -d nf0 -P backupserver and $HOST | head > /dev/null
fi
kill -9 $SLEEP_PID
exit 0
Hope this helps, Ralf.
--
- Intraplan Consult Gmbh Orleansplatz 5a 81667 Muenchen +49 89 45911-0 -
God, root, what is the difference? -Pitr (www.userfriendly.org: 11/11/1998)