1

In /etc/cron.hourly, there is one file:

-rwxr-xr-x  1 root root  117 Mar  8 20:33 myjob

myjob:

3,18,33,48 * * * * /usr/bin/python /home/me/src/myproject/src/manage.py myjobs > /home/me/log
3,18,25,27,29,31,33,35,37,48 * * * * /bin/echo "testing....." > /home/me/log

/etc/crontab:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

why the log file does not appear? Anything missing? myjob should run at 3,18, ... minute in each hour

2 Answers 2

3

Entries in cron.hourly are run by the run-parts mechanism (man run-parts for more info). And run-parts is choosy about what filenames it considers valid.

For example, giving your script an extension will make it invalid and result in the job not being run.

When adding a job to /etc/cron.hourly ( or .daily, .weekly, etc), always test afterwards that run-parts will actually run it by issuing the command: run-parts --test /etc/cron.hourly

0
1

The scrips in /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly are meant to be run at specific times, and do not are in the classic crontab format. Or put it simply, they are scripts, not files in the crontab format.

In the case of /etc/cron.hourly, they are just ran every hour.

you have to insert that line in crontab with crontab -e. For running in /etc/cron.hourly you would have to take out the 5 time fields to run only them every hour (e.g. taking out 3,18,33,48 * * * * ).

So in your case, either you move your script to /etc/cron.d or add to your crontab file the contents of myjob. take it out from the /etc/cron.hourly directory.

Back in /etc/crond.d, you need to put it as in as file as:

3,18,33,48 * * * * root /usr/bin/python ....
10
  • yep, it will work, I was forgetting that. Will add to the answer. Commented Mar 8, 2016 at 20:50
  • I added "3,18,25,27,29,31,33,35,37,48,53,54,55,56,58 * * * * root /bin/echo "testing....." > /home/me/log" to crontab, but not working. Commented Mar 8, 2016 at 20:54
  • take the word root out Commented Mar 8, 2016 at 20:55
  • not work. 1,3,5,18,25,27,29,31,33,35,37,48,53,54,55,56,58,59 * * * * /bin/echo "testingttt....." > /tmp/log Commented Mar 8, 2016 at 20:59
  • ps ax | grep -i cron? Commented Mar 8, 2016 at 21:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.