4

I have written a plist file and placed it into /Library/LaunchDaemons

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-    1.0.dtd">
<plist version="1.0">
<dict>
 <key>Label</key>
 <string>com.dotcafe.DCDMySQLBackup</string>
 <key>ProgramArguments</key>
 <array>
  <string>/Users/robdando/Webserverbackup/grab.sh</string>
 </array>
 <key>StartInterval</key>
 <integer>900</integer>
</dict>
</plist>

I have now got the script to file from terminal manually but I cannot seem to get it to run every 15 mins as I require, the script it calls logs onto an ftp server and pulls down a backup of mysql databases.

Cheers in advance.

DCD_Rob
  • 41
  • 1
  • 2

2 Answers2

2

Have you loaded the job into the correct launchd? Based on where you placed the file, it looks like you should be doing sudo launchctl load /Library/LaunchDaemons/com.dotcafe.DCDMySQLBackup.plist. Afterwards, can you sudo launchctl start com.dotcafe.DCDMySQLBackup?

I have had problems with a calendar-based launchd job not running when it should, even though it was loaded and worked fine when I launchctl started it. I was trying to run the job daily as my user, so my solution was to just turn it into a cron job.

Jeremy W. Sherman
  • 35,901
  • 5
  • 77
  • 111
  • I seem to have a similar problem; did you ever find out why it didn't run in launchd? I have other scheduled jobs that work fine, but one that doesn't (and, just like for you, it 'launchctl start's fine). – Nathan Sep 27 '12 at 23:23
-1

You haven't specified the Program key, so it can't run anything. Probably, you want to launch grab.sh without arguments.

I think there may be some permission issues, since you haven't specified UserName. Also, if your .bash_profile exports any environment variables which are used by the program, it may cause problems when running under launchd. (Assuming grab.sh doesn't use relative paths.) You can make a startup script for your program, which loads .bash_profile and then runs grab.sh.

khachik
  • 28,112
  • 9
  • 59
  • 94