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.

  • 1
    Use the full path to python - crontab does not use the normal shell environment – user151019 Sep 2 '18 at 12:51
  • 1
    cron will mail you if one of your crontab entries fail. Did you receive any mail? – fd0 Sep 2 '18 at 13:18
  • How could cron have my mail? @fd0 – Calculus Sep 2 '18 at 13:24
  • cron sends mail internally through postfix , a mail transfer agent. – fd0 Sep 2 '18 at 13:33
  • 1
    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. – Gordon Davisson Sep 2 '18 at 20:04

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":

  • is your script marked as executable? (e.g. chmod 755 /me/radio_alarm.py)
  • does your script begin with an appropriate shebang entry? (e.g. #!/usr/bin/python)
  • is your script written for the same version of Python that you're invoking? (e.g. mac os has only Python2, unless you've installed Python3 as part of 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 3 '18 at 11:07
  • @fd0: That should be a "canonical question" - you ask & answer. – Seamus Sep 3 '18 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .