1

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?

ecjb
  • 5,169
  • 12
  • 43
  • 79
  • Try changing `touch` to `/usr/bin/touch`. If that works, it's a problem with the path. If it doesn't work, then I hope someone else can spot the issue, because I can't see it :). – Gairfowl Jun 18 '23 at 05:59
  • Many thanks for your comment @Gairfowl. I tried your hint (and edited the question accordingly). Unfortunatelyit did not work. – ecjb Jun 18 '23 at 08:34
  • I don't see an obvious problem with your original solution. I would first verify, whether the crontab is processed at all. You could put the _touch_ command directly into your crontab, without a script. Is the file created (with a reasonable new timestamp)? Also: Under which user id is the cronjob executed? I don't know enough about Macos, but perhaps cron needs to be enabled somehow if you want to use it? I have the impression, that the problem is not related to zsh, and suggest that you ask this instead at [Ask Different](https://apple.stackexchange.com/). – user1934428 Jun 21 '23 at 09:36
  • Thank you for your comment @user1934428. So i added another task to the cronjob (namely `* * * * * cd /Users/user/Documents/cronjobs && echo check >> cron1.log`) and this one gets executed. – ecjb Jun 21 '23 at 17:01
  • I will ask the same question on Ask Differen then – ecjb Jun 21 '23 at 17:01

1 Answers1

0

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

ecjb
  • 5,169
  • 12
  • 43
  • 79