Not sure what I am doing wrong, I tried running this cron job where it should run this script (test.sh) where it copies my photos from one folder to a tmp folder but the cron job does not work unless it is in my home directory (or whatever directory when you just do a 'cd') I have tried the following and it works via command line but not on cron, can someone help. This is on Mac OS with the latest sw update
*/1 * * * * cd Desktop && ./test.sh
I've also tried the absolute path
*/1 * * * * /Users/helpme/Desktop/test.sh
My code for test.sh is below:
#!/bin/bash
rsync /Users/helpme/Desktop/test/* /Users/helpme/Desktop/tmp/
When I have the following in my crontab -e
*/1 * * * * /bin/bash '/Users/helpme/Desktop/test.sh' >> /Users/helpme/Desktop/backup.log 2>&1
I get the following in my log file
/bin/bash: /Users/helpme/Desktop/test.sh: Operation not permitted
Looked up the error, changed my privacy to full disk and still get the same error
UPDATE: Thank you to anonymous below in the comments for providing the article that solved the issue. Make sure to add cron to have full disk access. https://osxdaily.com/2020/04/27/fix-cron-permissions-macos-full-disk-access/
*/1 * * * * /path/to/test.sh
PATH
variable is typically not set so it is common to include the full path for the commands as well. So instead ofrsync
you may have to add its full path eg:/usr/bin/rsync
. If you typewhich rsync
you can find the command location. But based on this article it seems that thecrontab
executable needs additional permissions to run. Is this what you've done ? I have the impression it'scrontab
and not your script that is failing.