What could be preventing the backup script from running


I'm having trouble getting a simple backup script to run. The following script runs most of the time, but occasionally it fails entirely (without printing out any log information). Is there something in the script that could intermittently prevent it from running?

Even when it does run, the test log messages are sometimes delayed in appearing (as if the log file is not touched when it is written to, or the write to the log file is delayed), making diagnosis difficult.


printf "`date`: Start of Runkit backup Power Manager script:\n" >> ~/Library/Logs/Mine/tests.log

if [ $(mount | grep -c '/Volumes/Run Kit') != 1 ]
    printf "\tDon't copy: /Volumes/Run Kit not mounted\n" >> ~/Library/Logs/Mine/tests.log
    if [ $(pmset -g ac | grep -c 'Wattage') != 1 ]
        printf "\tDon't copy: Not plugged in\n" >> ~/Library/Logs/Mine/tests.log
        caffeinate -s -t 1200 &
        printf "\tDo copy: /Volumes/Run Kit mounted\n" >> ~/Library/Logs/Mine/tests.log
        /Users/Rax/Library/Application\ Support/SuperDuper\!/Scheduled\ Copies/SDUtil -i || open file:///Users/Rax/Library/Application\%20Support/SuperDuper\%21/Scheduled\%20Copies/Smart\%20Update\%20Run\%20Kit\%20from\%20Main.sdsp/Copy\%20Job.app

printf "`date`: End of Runkit backup Power Manager script:\n" >> ~/Library/Logs/Mine/tests.log

exit 0

Best Answer

I would first convert the printf statements to logger -p user.info statements since they are easily observed in the console app (and syslog) whenever the script runs.

You could also make a second script that just logs test messages or creates empty files /usr/bin/touch /tmp/test.$$.log to determine if your script above is the culprit or the Power Manager tool you are using is not reliably launching the script.

Also, you could try using an app like Lingon to have launchd start your script. The system uses that facility to run itself, so it' highly reliable and logs failures well if you ever need to troubleshoot a problem down the road.