sh script doesn't run from crontab

Viewed 19

I have a sh script that works fine if run it from terminal node /users/<my username>/Documents/work/cron-test/run-node.sh

#!usr/bin/env node
node /users/<my username>/Documents/work/cron-test/server.js

I setup crontab like this:

* * * * * sh /users/<my username>/documents/work/cron-test/run-node.sh >> /users/<my username>/documents/cron.log 2&>1

It shows no errors, but script doesn't execute

What am I doing wrong?

1 Answers

In my case I needed to specify exact path for node in sh script.

/Users/<my username>/.nvm/versions/node/v16.13.0/bin/node /Users/<my username>/documents/work/cron-test/server.js

And for MacOS it is important to give access to system for cron.

enter image description here

To find cron exec you can check this directory /usr/sbin/cron and drag it to Full Disk Access

enter image description here

Related