I set crontab but nothing happened,
crontab -l
03 04-22 * * * python /me/radio_alarm.py
What's the reason, the command works as intended in Linux.
Your crontab suggests that at 3 minutes past every hour from 04:00 through 22:00, invoke python to run /me/radio_alarm.py
If that's correct, and there are no other problems that we can't see*, the following correction should work:
03 04-22 * * * /usr/bin/python /me/radio_alarm.py
It is necessary to specify the complete path to python because the "cron user" does not have the same $PATH environment that you do under your user name.
* I assume that you have successfully run your script from the command line. If that is the case, you've probably cleared most of the potential errors below, but just in case here are the "usual suspects":
chmod 755 /me/radio_alarm.py) #!/usr/bin/python) homebrew, etc.) Finally, it never hurts to capture any stderr output while you're testing a new script. You can easily add an "error log" to your script as follows:
03 04-22 * * * /usr/bin/python /me/radio_alarm.py > ~/cronjoblog 2>&1
This will redirect any error output from your script to the file cronjoblog in your user's home directory.
Hope that helps. Let us know if you have further issues or questions.
cron's default PATH isn't documented in the manuals but if you care to suck it out of the binary file- strings /usr/sbin/cron | head -n10
– fd0
Sep 03 '18 at 11:07
cronwill mail you if one of yourcrontabentries fail. Did you receive any mail? – fd0 Sep 02 '18 at 13:18cronsends mail internally throughpostfix, a mail transfer agent. – fd0 Sep 02 '18 at 13:33postfixmay not be configured properly on a standard (non-server) macOS system. I'd do manual logging by adding something like>>/tmp/radio_alarm.log 2>&1to the crontab entry. Also, read serverfault's canonical question on crontab troubleshooting. – Gordon Davisson Sep 02 '18 at 20:04