LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 12-07-2006, 01:45 AM   #1
riotxix
LQ Newbie
 
Registered: Jul 2005
Location: England
Distribution: slackware (2.6.10)
Posts: 19

Rep: Reputation: 0
Crontab does not work


Distro: slackware 11.0.
Thanks for your time - I would like to be able to use cron!!!

It comes up a lot, but here's the situation:

I've written a script, chmod +x'd it, runs fine. Stuck it in my crontab to see if it was working - didn't, so I tried to run a command instead (a bit simpler):

To run every minute:

crontab -e:

*/1 * * * * /usr/X11R6/bin/numlockx

/etc/crontab:

*/1 * * * * root /usr/X11R6/bin/numlockx

Why isn't it working? I've followed everything.
 
Old 12-07-2006, 01:59 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Is your cron daemon running:
Code:
ps -ef|grep crond
If not you must edit /etc/rc.d/rc.M to make it run at startup.
 
Old 12-07-2006, 11:39 AM   #3
AlbinoJap
Member
 
Registered: Mar 2004
Posts: 36

Rep: Reputation: 15
Also, check your cron log (usually in '/var/log'). It will show if the job is actually being run.
 
Old 12-07-2006, 12:04 PM   #4
riotxix
LQ Newbie
 
Registered: Jul 2005
Location: England
Distribution: slackware (2.6.10)
Posts: 19

Original Poster
Rep: Reputation: 0
Thanks guys, but...

I grepped ps : yeah crond is running, and

cat /var/log/cron* ; there's nothing in those files..

Anymore?
 
Old 12-07-2006, 06:32 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you've tried it as root, have a look in root's mail box, cron usually sends an email to root if there's a problem.
 
Old 12-07-2006, 10:08 PM   #6
riotxix
LQ Newbie
 
Registered: Jul 2005
Location: England
Distribution: slackware (2.6.10)
Posts: 19

Original Poster
Rep: Reputation: 0
ok: cat /var/spool/mail/root:

This cron should be running right now: however, I do have an entry for last wednesday, but no subsequent ones:

Return-Path: <root@dmhosting.g.ysm.yahoo.com>
!! Where did all this yahoo crap come from? I didn't set that...

Received: from rx.rx.org (localhost [127.0.0.1])
by rx.rx.org (8.13.8/8.13.3) with ESMTP id kB6HF680029771
for <root@rx.rx.org>; Wed, 6 Dec 2006 17:15:06 GMT
Received: (from root@localhost)
by rx.rx.org (8.13.8/8.13.3/Submit) id kB6HF6X3029769;
Wed, 6 Dec 2006 17:15:06 GMT
Date: Wed, 6 Dec 2006 17:15:06 GMT
From: root@dmhosting.g.ysm.yahoo.com
Message-Id: <200612061715.kB6HF6X3029769@rx.rx.org>
To: root@dmhosting.g.ysm.yahoo.com
Subject: cron: /usr/X11R6/bin/numlockx

Error opening display!

--kB6LNXZs031260.1165440404/rx.rx.org--


Any ideas? Thanks....
 
Old 12-07-2006, 11:35 PM   #7
shawnbishop
Member
 
Registered: Dec 2005
Location: South Africa
Distribution: CentOS,Ubuntu,Fedora
Posts: 249

Rep: Reputation: 30
Can you run the script directly from command line, maybe a problem in your script??
 
Old 12-07-2006, 11:48 PM   #8
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Two things you need to do:

1. Set the DISPLAY environment variable explicitly in your script. All X programs need to know what display to execute on, and this is decided from the DISPLAY environment variable (or many of them can also use the command line option -display). When a job runs from cron it gets a minimal environment. This will not contain a DISPLAY, hence this error. You can read about the minimal environment of cron in the crontab page in section 5 of the manual. i.e.:
Code:
man 5 crontab
2. Make sure the program is authorised to access the X server. Exactly how this is set up is somewhat mysterious. Basically, do the DISPLAY thing, and if it doesn't work, check the mail file for root again. Probably you'll see something about Xauthority or magic cookies. Lets see if it works first and if not what the error is before we get into that though.
 
Old 12-08-2006, 10:14 PM   #9
riotxix
LQ Newbie
 
Registered: Jul 2005
Location: England
Distribution: slackware (2.6.10)
Posts: 19

Original Poster
Rep: Reputation: 0
Hey Matthew, here's what I did....

$ crontab -e;

added 1st line:

*/1 * * * * /sbin/reboot

it worked, crontab seems to be working.

Replaced the line with my script (which runs fine when executed manually):

*/1 * * * * /code/scripts/checkmail

This is as follows:

-----/code/scripts/checkmail------
#!/bin/bash
DISPLAY=":0.0" #I tried it without quotes too
if /usr/bin/fetchmail --check --silent ; then /usr/X11R6/bin/numlockx on ; else /usr/X11R6/bin/numlockx off ; fi

-----------------------------------

I got this display from `echo $DISPLAY` in an xterm when I started X. It doesn't seem to run correctly, and I've check root's mail and the /var/log/cron* logs, but they don't mention it running at all. Any ideas?


Again, thanks. I'm guessing it must be the display : although it does not show today (Saturday's attempt) to run it, or any in the past few days, I did find this entry in my mail from last Wednesday (can't believe it's taken this long to add a simple script to my crond...)

---MAIL---------------

Error opening display!
fetchmail: WARNING: Running as root is discouraged.

Subject: cron: if /usr/bin/fetchmail --check --silent ; then /usr/X11R6/bin/numl
ockx on ; else /usr/X11R6/bin/numlockx off ; fi
To: root@rx.rx.org

-----------------------

Last edited by riotxix; 12-09-2006 at 12:21 AM.
 
Old 12-09-2006, 02:51 AM   #10
riotxix
LQ Newbie
 
Registered: Jul 2005
Location: England
Distribution: slackware (2.6.10)
Posts: 19

Original Poster
Rep: Reputation: 0
crontab -e has begun to work.
/etc/crontab is being ignored.

I genuinely have *NO* idea why this happened.
I even took the $DISPLAY variable out of my script. It still works.

UPDATE:

I've been playing with the crontab -e file:

I've deleted the file /etc/crontab.
I've commented out checkmail script line.

For some reason, it is STILL running the line.

I think the problem here is that it is subjectively choosing whether to listen to the cron -e file : I'm not making this up. My crontab file has the line edited out, and it's still running the script every minute.

1. How should I fix this? How do I restart cron, and;
2. How can this possibly be happening? Surely this is unnacceptable behaviour, or I've got something wrong. Surely cron should start listening to the crontab -e file as soon as I save it.

UPDATE:
Now it's running as I want.

Basically, I think there must be delay between crontab -e updating to the crond (but that's odd, because I definitely left the cron file in the same state overnight in some cases). Either that, or I've been making mistakes - but I'm almost positive I haven't. I don't know, weird. It's working now, that's all that matters. But really, if someone could confirm that cron -e acts temporarily sometimes then it would put my mind to rest - I just don't know why it would start working like this all of a sudden. I know it sounds crazy but...oh well.

Last edited by riotxix; 12-09-2006 at 03:07 AM.
 
Old 12-09-2006, 10:24 PM   #11
riotxix
LQ Newbie
 
Registered: Jul 2005
Location: England
Distribution: slackware (2.6.10)
Posts: 19

Original Poster
Rep: Reputation: 0
Hi - I have something to confirm that cron might be working strangely...

I did a cat /var/log/cron* (date: Sun Dec 10 04:21:51 GMT 2006).

...
Dec 9 20:20:01 rx crond[8925]: USER root pid 13486 cmd /code/scripts/checkmail
Dec 9 20:24:01 rx crond[8925]: USER root pid 13609 cmd /code/scripts/checkmail
Dec 9 20:28:01 rx crond[8925]: USER root pid 13646 cmd /code/scripts/checkmail
Dec 9 20:32:01 rx crond[8925]: USER root pid 13761 cmd /code/scripts/checkmail
Dec 9 20:36:01 rx crond[8925]: USER root pid 13843 cmd /code/scripts/checkmail
Dec 9 20:40:01 rx crond[8925]: USER root pid 13873 cmd /code/scripts/checkmail
Dec 9 20:44:01 rx crond[8925]: USER root pid 13937 cmd /code/scripts/checkmail
Dec 9 20:47:01 rx crond[8925]: USER root pid 13994 cmd /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
Dec 9 20:48:01 rx crond[8925]: USER root pid 14071 cmd /code/scripts/checkmail
Dec 9 20:52:01 rx crond[8925]: USER root pid 14152 cmd /code/scripts/checkmail

....And then it just stops. And my script is no longer checking mail and turning the led on.

It started running at
Dec 9 08:25:35 rx crond[8925]: crond 2.3.3 dillon, started, log level 8
Dec 9 08:26:01 rx crond[8925]: USER root pid 8950 cmd /code/scripts/checkmail
(I changed my interval to 4 minutes) and stops at 20:42:01.

??WHY could it be doing this??!! It's 4:21, and my darn script has stopped running!!

UPDATE: Sun Dec 10 04:47:36 GMT 2006
I just re-ran ~$ cat /var/log/cron*; the files are empty again.

Last edited by riotxix; 12-09-2006 at 10:48 PM.
 
Old 12-09-2006, 11:39 PM   #12
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
When you ran crontab -e, what user were you logged in as? /etc/crontab controls the cron daemon. Each user has a crontab file, in Fedora they are in /var/spool/cron.

Maybe slackware is different, but in Frdora crontab -e simply invokes editing of the current user's crontab file. By now you may have made a bit of a mess. Can you restore /etc/crontab?

Only edit using crontab -e as the relevant user.

Last edited by billymayday; 12-09-2006 at 11:45 PM.
 
Old 12-10-2006, 04:18 AM   #13
riotxix
LQ Newbie
 
Registered: Jul 2005
Location: England
Distribution: slackware (2.6.10)
Posts: 19

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by billymayday
When you ran crontab -e, what user were you logged in as? /etc/crontab controls the cron daemon. Each user has a crontab file, in Fedora they are in /var/spool/cron.

Maybe slackware is different, but in Frdora crontab -e simply invokes editing of the current user's crontab file. By now you may have made a bit of a mess. Can you restore /etc/crontab?

Only edit using crontab -e as the relevant user.

I've always been logged in as root. When I first heard of /etc/crontab, it was a file that wasn't present on my system. I added a line to try it out, but then I removed it. I've always been using the crontab -e file (and that's the file all of my slackware default lines, ie. usr/bin/run-parts /etc/cron.hourly 1> /dev/null were put in).
 
Old 12-11-2006, 02:17 AM   #14
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
When I first heard of /etc/crontab, it was a file that wasn't present on my system
The file containing crontabs for all users is located under /var/spool/cron/crontabs. But there is no need to edit the root crontab directly. Just use crontab -e as root.
As for your script, you must export the DISPLAY variable:
Code:
#!/bin/bash
export DISPLAY=:0.0
if /usr/bin/fetchmail --check --silent ; then /usr/X11R6/bin/numlockx on ; else /usr/X11R6/bin/numlockx off ; fi
Before running the script you must also run
Code:
xhost +localhost
as the user that is currently logged-in, to allow other users to use your DISPLAY.

Note: If you are logged as root in X-windows there is no need to export the DISPLAY and run the xhost command

Last edited by bathory; 12-11-2006 at 02:18 AM.
 
Old 12-11-2006, 04:33 AM   #15
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
? root needs DISPLAY set too, the same as any user.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
crontab -e doesn't work after upgrade gbltech Slackware 3 04-21-2009 10:42 AM
crontab -e username doesn't work BiThian Linux - General 3 10-13-2006 10:31 AM
work with crontab juanb Linux - General 1 06-05-2004 09:29 AM
crontab does not work need help Xris718 Linux - General 10 04-18-2004 08:55 PM
crontab won't work John Galt Linux - General 32 08-20-2003 01:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:15 PM.

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