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
will mail you if one of yourcrontab
entries fail. Did you receive any mail?cron
sends mail internally throughpostfix
, a mail transfer agent.postfix
may 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>&1
to the crontab entry. Also, read serverfault's canonical question on crontab troubleshooting.