LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-22-2010, 01:25 PM   #1
fredrated
LQ Newbie
 
Registered: Oct 2010
Posts: 2

Rep: Reputation: 0
Who runs a cron job?


I have created a cron job under 'su' but it doesn't seem to run. I am not logged in as root, is that the reason the job won't run? Does a user-specific cron job only run if the user is logged on? And does an su-created cron job only run if root is logged on? Thanks.
Fred
 
Old 12-22-2010, 02:17 PM   #2
bluesword1969
Member
 
Registered: Jan 2010
Location: East Coast, USA.
Distribution: Gentoo, Debian, OpenBSD.
Posts: 70

Rep: Reputation: 25
Quote:
Originally Posted by fredrated View Post
I have created a cron job under 'su' but it doesn't seem to run. I am not logged in as root, is that the reason the job won't run? Does a user-specific cron job only run if the user is logged on? And does an su-created cron job only run if root is logged on? Thanks.
Fred
Welcome to LQO!

So, you're trying to run a cron job as root?

Give us an example of what you're trying to run.

The biggest gotcha on most cron jobs is how the asterisks appear:

0 3 * * * /usr/bin/yourexamplescript.sh

Just a random example.

Something better might be something like this:

http://www.thegeekstuff.com/2009/06/...ntab-examples/
 
Old 12-22-2010, 02:19 PM   #3
gb2312
LQ Newbie
 
Registered: Dec 2005
Posts: 20

Rep: Reputation: 6
Hi,

I tried it on my debian box, seems like you can setup root's crontab
and it would run without logging in as root. I suspect user crontab
should also run (the service running crontab runs as root I believe,
and it can change user id...)

~$ sudo crontab -l
no crontab for root

~$ sudo crontab -e
no crontab for root - using an empty one
crontab: installing new crontab

~$ sudo crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * date >> /tmp/root-cron.txt

~$ ls -l /tmp/root-cron.txt
-rw-r--r-- 1 root root 29 Dec 22 15:14 /tmp/root-cron.txt
 
Old 12-23-2010, 09:04 AM   #4
fredrated
LQ Newbie
 
Registered: Oct 2010
Posts: 2

Original Poster
Rep: Reputation: 0
I am trying to run the cron job in Suse Linux 11.3.
I have installed Apache, PostgreSQL and Drupal locally as I teach myself web development (I am a database developer hoping to expand my horizons)
My development site is at localhost and Drupal says to run the following periodically as a cron job:

0 9 * * * /usr/bin/wget -0 - -q -t 1 http://localhost/cron.php

I added the '0 9' since Drupal doesn't specify when to run it. I think this means run the job at 9:00 am every day, when my computer is booted up.

When I log in with su and invoke 'crontab -e' I get the above line.

I have verified that cron.php is at /srv/www....mysite.com/ and I have run cron.php manually so that should work.

Thanks for any insite you can offer.

Fred
 
Old 12-23-2010, 11:06 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
1. the cron service should be on by default. Try

ps -ef |grep cron |grep -v grep

2. There are cron.allow & cron.deny files, but usually the default is that anyone can run a cron job.

3. always ensure that all cmds & files accessed in a cron job are specified with the complete access path and are actionable by the cron user ie chk ownerships & perms.

4. as a rule, if cron has a problem it will email either the cron job owner or root. Try the mailx cmd from the cli to see.
See also /var/log/messages

5 see this link http://adminschoice.com/crontab-quic...Crontab%20file
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CRON job runs, but doesn't perform the task SUSE-OES SUSE / openSUSE 2 11-20-2009 03:30 PM
Cron Job only runs when it is manually started sinister1 Linux - General 4 02-25-2008 08:35 AM
cron job runs but will not write to logfile c_curtis Linux - General 10 06-30-2006 09:25 AM
cron job only runs halfway aunquarra Linux - General 15 01-31-2005 04:53 PM
Why Does One Cron Job Runs Twice? cpope67 Programming 4 11-16-2004 06:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:06 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration