On my Macos 11.6.1, I want to execute a script 'task1.zsh' with the following content
#!/bin/zsh
/usr/bin/touch /Users/user/Documents/cronjobs/hello.txt
echo hello >> /Users/user/Documents/cronjobs/hello.txt
the file task1.zsh
has the following permissions:
-rwxr-x--x 1 user staff 116B Jun 18 00:15 task1.zsh*
I inserted the following task with cronjob (with the following output of the command crontab -l
:
* * * * * /Users/user/Documents/cronjobs/task1.zsh
with this cronjob, however the file "hello.txt" is not created nor populated. I also tried to replace
* * * * * /Users/user/Documents/cronjobs/task1.zsh
by:
* * * * * cd /Users/user/Documents/cronjobs/ && ./task1.zsh
as well as
* * * * * /bin/zsh /Users/user/Documents/cronjobs/task1.zsh
or
* * * * * cd /Users/user/Documents/cronjobs /bin/zsh task1.zsh
without success.
However If I had the following other task to the cronjob list:
* * * * * cd /Users/user/Documents/cronjobs && /bin/zsh task1.zsh
* * * * * cd /Users/user/Documents/cronjobs && echo check >> cron1.log
the file cron1.log
gets created and gets populated by the string "check" (but the file hello.txt
does not get created nor populated)
What am I doing wrong?
As mentionned in the comment of Gordon Davisson in this question: https://apple.stackexchange.com/users/314206/ecjb, I went to Security and Privacy and granted full disk access to cron and it worked