0

So I am trying to write a launchd file to run a script on a Mac Mini as a specific user when they are not logged in. This is the plist file:

<?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.wintr.eodemail</string>
    <key>Program</key>
    <string>/Users/*myusername*/Desktop/testdaemon/testdaemon.sh</string>
    <key>StandardErrorPath</key>
    <string>/var/log/eod-email.log</string>
    <key>StandardOutPath</key>
    <string>/var/log/eod-email.log</string>
    <key>RunAtLoad</key>
    <true/>
    <key>StartCalendarInterval</key>
    <array>
        <dict>
            <key>Minute</key>
            <integer>20</integer>
        </dict>
    </array>
</dict>
</plist>

I have this placed in /Library/LaunchDaemons/ and it works fine running as the root user. Runs exactly when I tell it when no one is logged on, however when I add the UserName key it suddenly stops working:

<?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.wintr.eodemail</string>
    <key>Program</key>
    <string>/Users/*myusername*/Desktop/testdaemon/testdaemon.sh</string>
    <key>StandardErrorPath</key>
    <string>/var/log/eod-email.log</string>
    <key>StandardOutPath</key>
    <string>/var/log/eod-email.log</string>
    <key>RunAtLoad</key>
    <true/>
    <key>StartCalendarInterval</key>
    <array>
        <dict>
            <key>Minute</key>
            <integer>20</integer>
        </dict>
    </array>
    <key>UserName</key>
    <string>*myusername*</string>
</dict>
</plist>

When I unload and load the file, then check if it loaded correctly with sudo launchctl list | grep wintr it shows:

-       78      com.wintr.eodemail

And doesn't run. What am I doing wrong here?

  • Only the root user can write to /private/var/log, all other users should write logs to their home folder. ~/Library/Logs is one place that you could put the log file. – fd0 Sep 25 '17 at 19:36
  • I realized I didn't need those lines, removed them, and that did the trick. Thank you! – Nick Welna Sep 25 '17 at 21:02
0

As fd0 pointed out, my user could not write to the directory /private/var/log, since I did not need the logs I removed the following lines:

<key>StandardErrorPath</key>
<string>/var/log/eod-email.log</string>
<key>StandardOutPath</key>
<string>/var/log/eod-email.log</string>

And it started working! I could have also changed these to a directory my user can write to to fix the issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .