Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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):
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
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.
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
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.
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.
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.
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).
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.