Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 09-19-2006, 07:24 PM   #1
Registered: Sep 2003
Location: Eire
Distribution: Ubuntu 7.10
Posts: 344

Rep: Reputation: 30
script in cron.hourly not running hourly

I've put a file called 'test' in /etc/cron.hourly. Its code is:
touch /home/ja/hourly
I made it executable and waited for the turn of the hour, but nothing happened. The file did not appear in /home/ja.

Here is my crontab (I dont understand this file, even after reading the man pages)
# /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.
# This file also has a username field, that none of the other crontabs do.


# m h dom mon dow user command
17 * * * * root run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || run-parts --report /etc/cron.daily
47 6 * * 7 root test -x /usr/sbin/anacron || run-parts --report /etc/cron.weekly
52 6 1 * * root test -x /usr/sbin/anacron || run-parts --report /etc/cron.monthly
Old 09-19-2006, 08:08 PM   #2
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 64
Make sure your file /etc/cron.hourly/test is executable and has the shebang line (#!/bin/bash):

$ cd /etc/cron.hourly
$ ls -l
total 4
-rw-r--r-- 1 root root 35 2006-09-20 00:52 test
$ cat test
touch /home/ja/hourly
$ sudo chmod 755 test
$ ls -l
total 4
-rwxr-xr-x 1 root root 35 2006-09-20 00:52 test
Make sure /home/ja/hourly is writable by the user which runs the crontab. While this is almost certainly the case since cron.hourly runs as root, however there are some times when root will not be able to update the file. For example the filesystem in which that file resides is not mounted read/write, or the directory in which the file resides doesn't exist (I don't think touch creates directories if they don't already exist). Try echoing something and re-directing it into a file which is surely writable. Add this to the test script:
echo "cron job running at `date`" > /tmp/testcron
According to the /etc/crontab you posted, the cron.hourly runs at 17 minutes past the hour, check after this time.

Cron [at least the one which comes with Unbuntu] works out if there have been changes to the exitsing jobs by checking the timestamp on some directories. Check that the /etc/cron* stuff doesn't have screwy timestamps.

Make sure touch is in the PATH which is specified in your /etc/crontab, or modify your test script to speciy the full path to touch. The biggest cause of problems with cron jobs is that people assume they run with the same environment variables as their shell, and this is not true - cron jobs get a very "naked" environment, which may cause some programs to not be found, or not function as expected.

That's all I can think of right now.
Old 09-19-2006, 09:21 PM   #3
Registered: Sep 2003
Location: Eire
Distribution: Ubuntu 7.10
Posts: 344

Original Poster
Rep: Reputation: 30
Hi Matt,

Thanks for that informative post! I understand the crontab file better now. It turns out that the problem with my file was that it didn't have the 'shebang' line

Thanks again for your help. There are a lot of things I want to schedule on my kubuntu machine.

Best wishes,


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 09:09 AM
shutup cron.hourly mail reports darkleaf Linux - Software 4 06-27-2005 11:28 AM
Mandrake 10.0 = Hourly Crashes jjthebear Linux - Hardware 13 08-28-2004 12:59 PM
cron.hourly question Raw Kuts Linux - Newbie 1 08-18-2003 01:34 PM
How do I run/write an hourly cron? KoopaTroopa Linux - Newbie 1 08-16-2003 07:12 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:47 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration