New to crontab, I wanted to experiment.

Running the command crontab -l gave me the following answer crontab: no crontab for User_1

Every time I tried to issue a command like 1 16 24 10 6 ping -D -c 1 www.google.com I got the error "zsh: command not found".

Every time I modified the first number of the crontab command I got an error message saying, if for example 15 is the first number of the command, zsh: command not found: 15.

For info:

Mac OS X 10.12.6. zsh 5.8

which crontab: /usr/bin/crontab

/usr/bin is in my path.

  • 1 16 24 10 6 ping ... will only run when Oct 24th falls on a Saturday. To make it run every year use 1 16 24 10 * ping ..., to make it run each Saturday use 1 16 * * 6 ping ... – nohillside Oct 24 '20 at 15:11
  • I was testing the command, so I tried to run the command only one time just to see if it was working. I do not understand why when I issue the command crontab -l at 18:39 or later, I get the following answer 38 18 24 10 6 echo "test" >> ~/Downloads/test.txt. As the command has been run, shouldn't I get an answer saying no cron job is planned? I watched the Youtube Corey Schafer video about crontab and crontab -l is in his own words for "scheduled" jobs). Issuing crontab -r deinstalled this job from the crontab jobs list. – politicus Oct 24 '20 at 16:51
  • 1
    Your crontab file contains any commands/jobs you ever wanted to run via cron, even if their conditions will never be valid (you need to remove them manually from crontab). For one-off scheduling have a look at man at. – nohillside Oct 24 '20 at 18:02
  • at looks very interesting! Tried it on my Mac. Worked. Unfortunately, it is deprecated. From developer.apple.com "Older approaches, such as at jobs and periodic jobs are deprecated and should not be used." – politicus Oct 25 '20 at 8:15
  • This applies to both cron and at, one should use launchd instead. But the notice is there since ages, and as cron/at can easily be installed from source if necessary I wouldn’t worry too much. – nohillside Oct 25 '20 at 8:38

You need to edit your crontab to make changes. Run

EDITOR=nano crontab -e

to use the nano editor for this. Your (initially empty) crontab will be shown and can be edited (e.g. by adding the line you had in your question). Then press Ctrl-O, Return, Ctrl-X to save the changes and quit the editor.

  • OK, it is working now. Thank you! Is it fair to sum up the situation to "It couldn't work as your crontab command has to be in a crontab file to be working"? – politicus Oct 24 '20 at 16:32
  • 1
    @politicus True, the commands to be run by cron need to be in the crontab file. – nohillside Oct 24 '20 at 18:00

You must log in to answer this question.

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