Automate running a command (snapraid) at specific time of the day using crontab

I'm trying to automate running a snapraid command on specific time of the day automatically. Snapraid is a command line backup solution synchronizing data on disks with parity files. I have installed it using homebrew and works just fine from terminal when I give a command interactively.

I have been trying to use launchctl and crontab to automate it. Non worked so far - just nothing. Log file for a command is not touched after scheduled time.

I will create a separate topic for launchctl, but in the meantime, can somebody let me know if I might be missing something about using crontab?


My crontab:

00 17 * * * /usr/local/bin/snapraid sync -c /Volumes/DAS/config/MediaServerVPN/SnapRaid-config/snapraid.conf -l /Volumes/DAS/config/MediaServerVPN/SnapRaid-config/snapraid.log


I gave /usr/local/bin/snapraid full disk access.


Am I missing something? Any advice on troubleshooting it?


Thanks

Mac Pro, macOS 12.7

Posted on Aug 15, 2025 05:55 PM

Reply
9 replies

Aug 17, 2025 04:58 PM in response to amidsin

Yes, I know - although that question seems to have disappeared.


In any case, launchctl has some quirks that I never really spend enough time digging into, so I probably don't have the deeper esoteric knowledge you need. What I might recommend is a tool like Launch Control (https://soma-zone.com/LaunchControl/), that let's you build a launchctl .plist using a drag&drop interface that you can configure - and will give you visual indicators of warnings or errors that would cause it to fail. Good help files too.

Aug 18, 2025 11:06 AM in response to amidsin

I'm with wolfman here - launchd is the way to go, and there's no thread on the end of the link you provide.


That said, this should be the equivalent launchd.plist file for your crontab command. Save it as something like 'snapraid.plist' in ~/Library/LaunchDaemons and see how it goes:


<?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>snapraid.job</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/local/bin/snapraid</string>
                <string>sync</string>
                <string>-c</string>
                <string>/Volumes/DAS/config/MediaServerVPN/SnapRaid-config/snapraid.conf</string>
                <string>-l</string>
                <string>/Volumes/DAS/config/MediaServerVPN/SnapRaid-config/snapraid.log</string>
        </array>
        <key>StartCalendarInterval</key>
        <array>
                <dict>
                        <key>Hour</key>
                        <integer>17</integer>
                        <key>Minute</key>
                        <integer>0</integer>
                </dict>
        </array>
</dict>
</plist>


Aug 18, 2025 03:28 PM in response to Camelot

Thank you for offering help, Camelot.

As I mentioned I have tried both ways. For some reason my other thread went away somewhere. Perhaps it makes more sense to pursue launchctl method.


Based on your suggestion and my previous research I have compiled plist file (at the end of my message). It is written as much as possible to replicate my successful interactive runs of the program including key to run as my own user and also the environment PATH variable.

I'm using two following commands to load it:

sudo cp ./snapraid-sync-service.plist /Library/LaunchDaemons/
sudo launchctl bootstrap system /Library/LaunchDaemons/snapraid-sync-service.plist


I'm getting error:

Bootstrap failed: 5: Input/output error


I'm doing something wrong while installing it? Or is something wrong with my plist file?


My plist file (snapraid-sync-service.plist):

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>me.dgor.snapraid-sync-service</string>

        <key>ServiceDescription</key>
        <string>Regular syncronization of the snapraid backup on storage and media drives</string>

        <key>Program</key>
        <string>/usr/local/bin/snapraid</string>

        <key>ProgramArguments</key>
        <array>
            <string>sync</string>
            <string>-c</string>
            <string>/Volumes/DAS/config/MediaServerVPN/SnapRaid-config/snapraid.conf</string>
            <string>-l</string>
            <string>/Volumes/DAS/config/MediaServerVPN/SnapRaid-config/snapraid.log</string>
        </array>

        <key>UserName</key>
        <string>dg</string>

        <key>EnvironmentVariables</key>
        <dict>
            <key>PATH</key>
            <string>
               /usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
            </string>
        </dict>

        <key>StartCalendarInterval</key>
        <dict>
            <key>Hour</key>
                <integer>15</integer>
            <key>Minute</key>
                <integer>20</integer>
        </dict>

        <key>RunAtLoad</key>
        <false />

    </dict>

</plist>

Aug 18, 2025 04:32 PM in response to amidsin

I have made more progress - because of gremlin of something, it seems like after restart, my service is being properly installed.


I can see it installed:

cp ./snapraid-sync-service.plist /Library/LaunchDaemons/
sudo launchctl bootstrap system /Library/LaunchDaemons/snapraid-sync-service.plist
sudo launchctl list | grep snapraid
-	0	me.dgor.snapraid-sync-service


I try running the service:

sudo launchctl kickstart -kp system/me.dgor.snapraid-sync-service
service spawned with pid: 1648

But as a result, the log file, which populated by executing snapraid sync ... command is not touched. For some reason, it appears that service is not actually running.


Any additional advice on why launctl is cannot run this service?

Would appreciate any help. I'm going crazy with this between launchctl complexity and crontab not for some reason as well.

Aug 18, 2025 08:28 PM in response to amidsin

Bottom line, the service has started working when I switched to using <key>ProgramArguments</key> only, without <key>Program</key>, just as Camelot has suggested. Credit goes to him.


My resulting plist file:


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>me.dgor.snapraid-sync-service</string>

        <key>ServiceDescription</key>
        <string>Regular syncronization of the snapraid backup on storage and media drives</string>

        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/bin/snapraid</string>
            <string>sync</string>
            <string>-c</string>
            <string>/Volumes/DAS/config/MediaServerVPN/SnapRaid-config/snapraid.conf</string>
            <string>-l</string>
            <string>/Volumes/DAS/config/MediaServerVPN/SnapRaid-config/snapraid.log</string>
        </array>

        <key>UserName</key>
        <string>dg</string>

        <key>EnvironmentVariables</key>
        <dict>
            <key>PATH</key>
            <string>
               /usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
            </string>
        </dict>

        <key>StandardOutPath</key>
            <string>/var/log/snapraid-sync-service.log</string>
        <key>StandardErrorPath</key>
            <string>/var/log/snapraid-sync-service.err</string>

        <key>StartCalendarInterval</key>
        <dict>
            <key>Hour</key>
                <integer>23</integer>
            <key>Minute</key>
                <integer>30</integer>
        </dict>

        <key>RunAtLoad</key>
        <false />

    </dict>

</plist>

Aug 19, 2025 11:11 AM in response to amidsin

> the service has started working when I switched to using <key>ProgramArguments</key> only, without <key>Program</key>


Yup, that would make a difference.


Program - launches the specified executable as-is. No command-line arguments are passed in.

ProgramArguments - launches the specified executable noted in the first dictionary item. Additional dictionary items are passed as arguments/parameters to the executable.


So your original use of Program would result in the app launching, but none of the parameters being passed in.

Automate running a command (snapraid) at specific time of the day using crontab

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.