LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 09-19-2006, 06:24 PM   #1
unholy
Member
 
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:
Code:
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.

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 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, 07:08 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

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

Code:
$ cd /etc/cron.hourly
$ ls -l
total 4
-rw-r--r-- 1 root root 35 2006-09-20 00:52 test
$ cat test
#!/bin/bash
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:
Code:
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, 08:21 PM   #3
unholy
Member
 
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,
unholy
 
  


Reply


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 08:09 AM
shutup cron.hourly mail reports darkleaf Linux - Software 4 06-27-2005 10:28 AM
Mandrake 10.0 = Hourly Crashes jjthebear Linux - Hardware 13 08-28-2004 11:59 AM
cron.hourly question Raw Kuts Linux - Newbie 1 08-18-2003 12:34 PM
How do I run/write an hourly cron? KoopaTroopa Linux - Newbie 1 08-16-2003 06:12 PM


All times are GMT -5. The time now is 07:30 PM.

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