I'm hoping someone can help me with this. I've been working on it literally all day...
I want a LaunchDaemon to execute a shell script at startup. Here is my plist file, located at /Library/LaunchDaemons/com.mhi.backup.plist:
<?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.mhi.backup</string>
<key>UserName</key>
<string>Joel</string>
<key>GroupName</key>
<string>Admin</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/mhi_websites_backup.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
It executes correctly when I load it from the terminal (launchctl load /Library/LaunchDaemons/com.mhi.backup.plist), but not on startup.
Here is my script, for reference:
#!/bin/bash
sleep 15 #delay script to ensure time for network connection
ssh user@hostname << HERE
mysqldump -u <user_name> -pPASSWORD --all-databases | lzma > alldatabases.sql.lzma
tar cfa backup-`date '+M%mD%dY%y'`.tar.lzma webapps alldatabases.sql.lzma
exit
HERE
scp user@hostname:backup-`date '+M%mD%dY%y'`.tar.lzma /Users/Joel/Desktop
Could someone please help?
Thanks so much,
JG
Is the plist owned by root? If a plist in
/Library/Launch{Agents,Daemons}/
is not owned by root, it can be loaded withlaunchctl
withoutsudo
, but it is not loaded at login.You could also try moving the plist to
/Library/LaunchAgents/
and adding aLimitLoadToSessionType
key:See the Daemons and Agents tech note.