0

I wanna run a script using crontab in every minute. The script is located at /Users/robin47/Desktop/script/demo.sh. As a side note, I give the execute permission of demo.sh file with chmod +x demo.sh command.

But it doesn't execute the script. Here is the process I'm following:

Run crontab -e from the terminal.

robin47@mac-pro ~ % crontab -e

this open a file(crontab.xxxxxxx) in nano which is located under tmp folder, as an example File: /tmp/crontab.V4DcXEJU8g.

This is my crontab.xxxxxxx file:

SHELL=/bin/bash 
PATH=/bin:/sbin:/usr/bin:/usr/sbin
* * * * * /bin/bash /Users/robin47/Desktop/script/demo.sh

Get from here, this doesn't execute my demo.sh script.

If I run sh command from terminal like sh demo.sh, it works. And if I directly echo(or run any command like touch, mkdir) in crontab like this

SHELL=/bin/bash 
PATH=/bin:/sbin:/usr/bin:/usr/sbin
* * * * * echo 'hello' >> /Users/robin47/Desktop/script/text.txt 

It also works. But doesn't run the script using crontab. I appreciate your help, Thanks.

This is my demo.sh file:

#!/bin/sh

echo "hello world" >> /Users/robin47/Desktop/script/text.txt
Robin
  • 4,902
  • 2
  • 27
  • 43
  • (1) If you invoke the script in the way you are doing it, setting the x-bit is not necessary. (2) "does not work" is not the best problem description imaginable. Provide some reasonable error description by telling, which statement in the script works differently from what you expect. (3) For debugging, run the script by `bash -x ...../demo.sh` – user1934428 May 19 '22 at 06:21
  • 1
    Recent versions of macOS restrict access to "personal" data, including anything in the Desktop folder (and a number of other places). See [this question on Ask Different](https://apple.stackexchange.com/questions/332673/what-and-how-does-macos-mojave-implement-to-restrict-applications-access-to-pers). I'd recommend moving the script and the things it accesses to a non-private area. If that's not possible, you'll need to grant access to cron (see [this question](https://apple.stackexchange.com/questions/378553/crontab-operation-not-permitted), though it shouldn't need Full Disk Access). – Gordon Davisson May 19 '22 at 06:45
  • @GordonDavisson after giving access it works. – Robin May 19 '22 at 09:24

1 Answers1

-2

refer below site for cron entries , also check your script have executable permission chmod oug+x demo.sh

https://crontab.guru/

salim ep
  • 35
  • 5
  • script has the executable permission, can you please elaborate your answer what can be problem(s). – Robin May 19 '22 at 05:15