Shell command works fine as is, but not when executed from crontab. What's the difference?

I created a small workflow with the Automator App, and I want it executed periodically. For that I created an entry in crontab. The problem is that running the workflow straight from the Terminal works perfectly, but when executed from crontab, the "Connect To Servers" stage fails with the following error:

The action “Connect to Servers” encountered an error: “Failed to connect to server “smb://andreas@"serverIp"”.”

The server is definitely available, and indeed, running the workflow from within the App or using the exact same command I entered in the crontab file in the Terminal works perfectly.

This is my crontab:

* * * * * /usr/bin/automator /<path>/<filename>.workflow >> /"path"/"filename".workflow.out 2>&1

And again, running

/usr/bin/automator /<path>/<filename>.workflow >> /"path"/"filename".workflow.out 2>&1

in the terminal works.

What's the difference and how can I fix it?

UPDATE: I don't think it's missing env variables. I used the env command in my normal terminal and pasted all the declarations into the crontab file to no avail.

UPDATE 2: I switched to using launchd as a workaround, but I'm still curious as to why it didn't work with cron.


Solution 1:

Might you be running a version of macOS where cron needs to be granted disk access?

  • On Catalina, how can a cronjob get permission to touch files on a USB disk?