It runs as a cron job once an hour between 10.00 and 22.00
When the laptop is sleeping/hibernating (never got the hang of which is which) the script obviously will not run. When I reopen the laptop the script starts running after a minute. The problem is that it reports that the lock file has been found, but it doesn't exist, and then does not exit after the aborted message but continues and completes the rsync. I have tested with the lock file being present and it runs as expected exiting after the aborted message.
Why is it "finding" the lock file when it isn't there? And why does it ignore the exit?
How can I fix it?
Thanks.
Code: Select all
#!/bin/bash
STIME=`date +%d-%m-%Y-%T`
echo "*********** Audio to S3TB $STIME ***********"
file="/home/xxxxxxxx/rsync.lock"
if [ -f "$file" ]
then
echo "Lock file found."
SUBJECT="Audio to S3TB"
TOEMAIL="xxxxxxxx@cccccccc"
/usr/bin/mail -s "$SUBJECT" "$TOEMAIL" <<END
Lock file found for Audio S3TB
END
STIME=`date +%T`
echo "*********** Aborted at $STIME ***********"
exit
else
echo "Creating lock file"
touch $file
echo "Created lock file"
fi
rsync -lpogtr --stats --rsh=ssh --recursive --times --delete --exclude '.*' /home/xxxxxx/ /mnt/xxxxxxx
rm $file
if [ -f "$file" ]
then
echo "Could not remove lock file."
else
echo "Lock file removed"
fi
STIME=`date +%T`
echo "*********** Finished at $STIME ***********"