launchd unable to access external drive

I'm trying to automate a script to backup a couple of directories on my Mac mini (macOS 11.4). Some of the files I want to backup are stored on an external drive that is mounted to /Volumes/SHASTA. I wrote up a quick launchd script just to see if it can access that directory but it seems to be erroring out. Here's what I wrote up:

<?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>local.resticd</string>
        <key>StandardOutPath</key>
        <string>/Users/myname/test.txt</string>
        <key>StandardErrorPath</key>
        <string>/Users/myname/test2.txt</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/bin/caffeinate</string>
            <string>/bin/ls</string>
            <string>/Volumes/SHASTA</string>
        </array>
        <key>WorkingDirectory</key>
        <string>/Users/myname/restic</string>
        <key>StartCalendarInterval</key>
        <dict>
            <key>Weekday</key>
            <integer>0</integer>
            <key>Hour</key>
            <integer>23</integer>
            <key>Minute</key>
            <integer>0</integer>
        </dict>
    </dict>
</plist>

Unfortunately the only output I get from this script is:

ls: SHASTA: Operation not permitted

in the standard error output. I'm not sure what to even try to get launchd permissions to access this drive since it already runs at root elevation.


Solution 1:

I resolved this issue. The problem ended up being that the caffeinate executable (which I was using because when I add my backup script later I want to keep the machine from going to sleep) did not have full disk permission. This prevented it from being able to access the external drive. Adding caffeinate to the full disk permission list in settings resolved the issue.