launchd file runs manually but not automatically

若如初见. 提交于 2019-12-07 13:42:07

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4379095/launchd-file-runs-manually-but-not-automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!