LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   crontab won't work (https://www.linuxquestions.org/questions/linux-general-1/crontab-wont-work-39705/)

John Galt 12-29-2002 06:03 PM

crontab won't work
 
I am having a problem with crontab..mainly that it won't work. I've played with it for over an hour and still can't get it to run anything at all. Currently I have a test file called "test". All that is inside of it is

* * * * * xclock
[blank line]

I would like to use crontab but I couldn't even get this test file to run. As u can see its set to run every minute and launch xclock. I have tried other applications and also tried using applications from their own dir such ass

* * * * * /usr/X11R6/bin/xclock
[blank line]

I have tried changing the asterisks to numbers coresponding to the current time such as.

30 * * * * /xclock
[blank line]

Trying something like this on the 29th minute of the hour. Still to no avail. I have multiple test files now..As far as I know the only syntax involved in loading the file into the crontab database is

crontab "filename"

This command seems to do something so I assume that is not the problem but after playing with it for so long. I can't figure out what the problem is. Anyone got any ideas?

pjcp64 12-29-2002 06:53 PM

Have you verified that crond is running? ps -ef | grep cron

You might also want to look at the cron log. /var/log/cron
This should give you an insight into the problem.

Were you editting the crontab with a crontab -e

I'd also consider trying something even less complex than xclock.
/bin/date >> /date.log for instance.

Hopefully this will work. If it does, then the problem with your xclock job is probably that you need to specify the entire path. Try "which xclock"

John Galt 12-29-2002 07:44 PM

yes I've verified crond is running.

I checked the cron log and the error and warnings files were both empty

I was editing the crontab w/ emacs. crontab -e opens up vim and I hate vim

I just tried /bin/date >> /date.log

Still won't work. Also I have tried the entire path when trying xclock. Also the /bind/date >> /date.log already has the entire path so I don't think that is the issue. As far as I can see with everything I've read about crontab now online I should be a freaking crontab expert..yet I can't get it to work still. Thanks for the reply though

pjcp64 12-29-2002 08:27 PM

Crontab Issue
 
Try the following:

crontab -l ( this lists the entries in crontab, I bet it's blank. )
crontab -e ( to add the entry you'd like )

The "-e" option is used to edit the current crontab using the editor
specified by the VISUAL or EDITOR environment variables. After you
exit from the editor, the modified crontab will be installed automatically.

I've gotten used to vi and vim, but you could change the environment variables to use emacs if you like.
As you can see, the crontab -e does more than just modify the file.

I'm assuming you're doing this as root. If not, verify that you either don't
have any /etc/cron.allow and /etc/cron.deny files. If you do have these files,
validate their values.

John Galt 12-29-2002 08:39 PM

aha...I found a new site the had a little more info and fixed the initial problem I was having. kinda stupid on my part but I didn't know how it worked. Turns out when crond starts up it loads all the crontab files into memory..then tries to execute them. Well when crontab started (4 days ago) I had no crontab files at the time. So none were loaded into memory. Hence restarting crond it now tries to run my crontab every minute. Onto the new problem.

"sendmail: fatal: my hostname localhost is not a fully qualified name - set myhostname or mydomain in /etc/postfix/main.cf"

That is the exact error I get. My problem is I could give a crap about using "mailto" in my crontabs. I don't know why it is so adamante upon this setting. I don't want to set myhostname or mydomain. Is there any generic setting I can add that will disable this feature or at the very least..keep things local. I have no interest in mailing anything to anyone w/ crontab

pjcp64 12-29-2002 09:02 PM

Bingo
 
That's good news. I believe crontab -e will update the settings in memory without having to actually cycle the cron daemon itself.

As far as why your cron is trying to email, try:

[root@rh01 etc]# ll -d /etc/cron*
drwxr-xr-x 2 root root 4096 Oct 27 12:08 cron.d
drwxr-xr-x 2 root root 4096 Oct 30 22:02 cron.daily
drwxr-xr-x 2 root root 4096 Oct 27 12:06 cron.hourly
drwxr-xr-x 2 root root 4096 Oct 27 11:50 cron.monthly
-rwxr-xr-x 1 root root 309 Oct 27 12:07 crontab
drwxr-xr-x 2 root root 4096 Oct 27 11:50 cron.weekly

These files have entries in them, and I bet one of them is trying to email using
/etc/postfix. If the job that uses it needs to run, try adding a 2> /dev/null to the end of its cron entry. This'll reroute any errors to the bit bucket.

My hostname is just RH01 without a domain or anything. My /etc/postfix/main.cf has the following line:

mydestination = $myhostname, localhost.$mydomain

John Galt 12-30-2002 02:54 AM

Well I think thats definately the right track..after checking all the above folders I found a total of 4 references to postfix. 3 of them were simply scripts (all identical)to check postfix for errors which would seem to be what I'm getting. I'm going to have to grep the contents of every file on the drive to find any more of those scripts to "check" postfix and disable them. Annoying but hell i'll let it run and go to bed :-). If you can think of the locations before then that would be hella helpful. But you've already been very helpful. Thanks for the great reply

NGraphiX 12-30-2002 04:01 AM

A Ayn Rand fan in the GNU world .. cheers!

John Galt 12-30-2002 10:49 AM

;-)

pjcp64 12-30-2002 08:31 PM

That's good news John...
 
I don't quite follow why you'd need to check the entire drive though. The cron jobs are probably the only ones that run this regularly. After disabling the postfix cron jobs, any errors you get would be the result of something you're currently running.

But anyway, it'll be a good exercise in recursive grepping. I'd recommend a process something like this:

find / -type f | xargs file | grep text$ | cut -f1 -d":" | xargs grep postfix * > ~/regrep.out &

The only problem is that the final output doesn't show you the entire path to the filename itself. You could create a list with:
find / -type f | xargs file | grep text$ | cut -f1 -d":" > ~/file.list.out &
but then you'd have to cross-reference. I'm sure there must be a better way!

Have fun!

Thom

John Galt 12-31-2002 01:18 AM

ummm.....yeeeaaaaaaaaaaa...i'm more confused now than ever. Lets begin the tale of some really weird events in "The history of linux according to John" (John isn't my real name btw as Ngraphix mentioned). So while I'm playing with all this wonderful stuff today I happen to by chance print the date.log file. For the last 24 hours my test crontab gave the instruction that you recommended before "/bin/date >> date.log". Well what do you know it had the date/time of every minute for the last 24 hours. It was working. So I'm like ok. No more errors either. So I changed the test file to run xclock. Didn't work. Then I remembered I had to rerun the crond daemon. So I did that now I'm back to the postfix errors again. Whats even more strange is that even though "/bin/date >> date.log" is not mentioned anywhere anymore it is still piping date into the date.log file every minute even after changing the crontab and restarting crond. my crontab-l now reads

* * * * * xclock
[blank line]

I'm so hella confused now I have no clue where to go from here. You have been so helpful I figured maybe u could figure this doozy out.

BTW my real name is Shane ;-)

pjcp64 12-31-2002 06:10 AM

Shane,

Maybe we can figure this thing out over the phone... I'll send you an email with my number. You could call either this evening ( 6-8 CST ) or tomorrow during the day.

Thom

pjcp64 12-31-2002 09:16 PM

John,

If I were you i'd:
1) blank out your date.log file.
2) I'm assuming the postfix error check in the cron directories haven't reappeared.
3) crontab -e to modifiy your crontab back to * * * * * /bin/date >> date.log
( I know you hate vim...... but the "-e" is important and it's only 31 letters altogether )

I bet this fixes it. I'm guessing that xclock is erroring for some reason relating to the fact that it doesn't care to run from cron. Because of this its trying to send a postfix email ( to root@localhost ??? ).

If it doesn't fix things, it might be that all of our shanigans have put a wierd setup into memory. Try rebooting to clear all the memory out and see what happens.

xclock might also be erroring out because it can't find the command in the $PATH. It's best to use the full paths in cron.
* * * * * /usr/X11R6/bin/xclock

One question, why do you want to run xclock from cron anyway?

Hope this helps.

Thom

broadaxe 02-19-2003 01:51 PM

John,
You can change the default editor that crontab uses by setting your VISUAL environment variable. In bash, you may just type, at the prompt,

export VISUAL=emacs

provided emacs is in your default path, this would change the editor for a bunch of stuff, including crontab. You can also include the line above in your .bash_profile to make the change permanent. You might also want to include,

export EDITOR=emacs

while you are at it.

Hope this helps.

hershst 05-27-2003 03:30 PM

More frustration with cron
 
I am following up on John's trail.
I also went to crontab -e (both as roor and as Admin)
and typed
* * * * * /bin/date >> /date.log
and -- failure.

No /etc/cron.deny or /etc/cron.allow
Restarted service crond on Red Hat 8
(Also no mention of root or Admin in/etc/crontab,
but they don't have to be there, right?)
Feeling frustrated!

dorian33 05-27-2003 04:22 PM

hi guys...
maybe it is not a matter for this problem (I did not study them, only read the first sentence of post#1) but to avoid any problems never use 'test' name - 'test' have a special meaning for bash

pjcp64 05-27-2003 06:25 PM

CRONic Problems
 
Hershst,

Check the following ( as root ):

1. crontab -l <== that's an "el"
This should verify that * * * * * /bin/date >> /date.log should be running.

2. ps -ef | grep [c]rond
To ensure that crond is running.

3. ll /var/log/cron
These are the cron logs. Observe the timestamp; it should tell you when the last cron job ran.

4. tail /var/log/cron
This will give you info on the last cron jobs that ran.

5. Have you received any localhost mail indicating a problem?
( use pine or elm to check )

6. You are doing this as "root"? If not, you'll probably have a permissions error when you try to create /date.log

Let me know.

Thom

pjcp64 05-27-2003 06:44 PM

Also,

7.
echo $EDITOR ( mine is vi )
echo $VISUAL ( mine is blank )

8. When you do a "crontab -e" do you get the following message:

crontab: installing new crontab

9. ll /var/lock/subsys/crond ( mine has a size of zero )

10. ll /tmp/crontab* ( I don't show any )

Redhat does it differently than a standard Unix system.
You might have to work with the /etc/cron* directories and files to get what you need

ll -d /etc/cron*

/etc/crontab should handle funky time intervals
There others would be used for standard time intervals ( weekly etc... )

/etc/init.d/crond restart to update the changes.

pjcp64 05-27-2003 06:58 PM

P.S.

I just did a crontab -e
Added * * * * * /bin/date >> /date.log
( no tabs, only blanks )
It worked.

???

Thom

hershst 05-28-2003 08:52 AM

As you can see below, I have been following the suggestions of pjcp64.

[root@linux cron]# crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.7598 installed on Wed May 28 09:46:57 2003)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
*/1 * * * * /bin/date >> /root/log.log



[root@linux root]# ll /var/lock/subsys/crond
-rw-r--r-- 1 root root 0 May 27 16:16 /var/lock/subsys/crond

[root@linux root]# cd /var/spool/cron
[root@linux cron]# ls

[root@linux cron]# ll /tmp/crontab

[root@linux cron]# crontab -e
crontab: installing new crontab

However, my results are not good.
[root@linux cron]# less /root/log.log
/root/log.log: No such file or directory

pjcp64 05-28-2003 03:12 PM

CRONic Problems
 
You say that
ll /var/spool/cron doesn't show any files?
That's odd, because a file named root should exist ( since you're using root as the ID ).
This file should contain your crontab info.
You could always add that file manually, ie.
vi /var/spool/cron/root and add
* * * * * /bin/date >> /root/log.log

Then restart cron by:
/etc/init.d/crond restart

I bet crontab -l would show the /bin/date command this time.

I'm at a loss as to why it's not working automatically with a crontab -e though.

Could you show me your $EDITOR and $VISUAL values?

Thanks.

Thom

hershst 05-28-2003 08:27 PM

There were NO entries appearing as $EDITOR and $VISUAL. Strange.
My editor clearly is vim.
My OS is Red Hat Linux 8.0 .

(I even added a specific /etc/cron.allow to no avail.)

pjcp64 05-28-2003 09:56 PM

It's probably in your path and you've probably got an alias vi=vim defined.
I think that EDITOR needs to be defined ( I forget why ) for the crontab -e process to work correctly.

Try: export EDITOR=vi
and then try the crontab -e

I'm not sure that'll fix it though. I unset my EDITOR value and my crontab -e still worked. ???

hershst 05-29-2003 01:26 PM

Sorry, pjcp64, but there was no differnece when I added export EDITOR=vi

pjcp64 05-29-2003 06:29 PM

CRONic Problems
 
I'm at a loss. :-(

Normally, when you "crontab -e", a temporary file is created like /tmp/crontab.12345
You can check by opening a second window and type "ll /tmp/crontab*

I normally set my editor during the bootup process but that shouldn't make a difference.

Did you try directly editting /var/spool/cron/root and restarting crond? If so, does a "crontab -l" show your entries?

I guess you could edit /etc/crontab and restart cron.

If you get it resolved please post the solution for me. I'll keep an eye out a solution too.

Good Luck!

Thom

hershst 05-30-2003 03:41 PM

When I execute "crontab -e" the temporary file is created.
It is named when I execute "crontab -l"
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.11714 installed on Thu May 29 14:29:27 2003)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
*/2 * * * * /usr/bin/perl /var/www/mail/batch/incoming.pl
*/10 * * * * /usr/bin/perl /var/www/mail/batch/outgoing.pl
*/2 * * * * "/bin/date >> /root/log.log"

However, on several of my Red Hat Linux 8.0 boxes,
/var/spool/cron/root is NEVER created as shown in the next few lines.
# cat /var/spool/cron/root
cat: /var/spool/cron/root: No such file or directory


Please note that PANDA reports virus infections on 3 of these computers with a report like this one:

cat /var/log/panda/pavcl.log
[ Fri Apr 25 14:10:40 2003 ] Univ.A in /dev/tux/tools/lst/stk
[ Fri Apr 25 14:23:36 2003 ] Univ.A in /dev/tux/tools/lst/stk
[ Fri Apr 25 14:24:04 2003 ] Univ.A in /dev/tux/tools/lst/stk

PANDA claims to have cleaned the files, but it may not have undone all of the damage.

On the remaining computer with does not create /var/spool/cron/root,
there was an error recently that /tmp was deleted. This may have been a manual error committed by the programmer. I don't know. Other related damage may have occurred.

So it appears that I am unable to set my own crontab jobs only on these compromised boxes. System cron jobs DO work even on the compromised boxes. My own cron jobs do work on uncompromised boxes.

So the problem seems to lie with the system, not the manner of using cron.

thlware 07-02-2003 03:17 AM

Cron
 
How do i check if my scheduled job was run successfully is there a command that we can use except $ crontab -v in my system it does not work and when i use $ mail you can only see details if the scripts you set on cron were executed in "short how can i see when did the last time my cronjob was executed.

pjcp64 07-05-2003 06:26 PM

Take a look at /var/log/cron

It should list evrey cronjob that ran.

yktang 07-12-2003 02:35 PM

I have the same problem. Cron job is not working.

I used crontab -e to modify my test run
* * * * * /usr/bin/mozilla
but nothing showed up.

Checked crond is running.

Anyone can help??

Y0jiMb0 07-21-2003 04:53 AM

I think I have the same problem as yktang (and others). For instance, if I use crontab -e and try

20 * * * * /bin/date

it doesn't seem to work, but if I write

20 * * * * /bin/date >> ~/file.txt

it works. The same happens with many other commands. Nevertheless, if I like to play a song with

20 * * * * /usr/bin/mpg123 ~/9.mp3

or if I want to start the lmule program using

20 * * * * /usr/bin/lmule

It doesn't work.

Anyone has an idea about what can I do to run lmule with cron?

Blinker_Fluid 07-21-2003 09:34 AM

Dunno if it helps or not but I think the commands like mozilla and the Xclock need a display variable set for them to work from cron. Kind of like if you log into a remote system and don't have your DISPLAY variable set. You can run mozilla but who knows where it's going to pop up. (if it does at all)
As far as the date one it probably spits it out to standard output (so it's not going to put it in your console window.)

Y0jiMb0 07-22-2003 12:46 AM

Thank you, Blinker_Fluid, for your comment! Now I see why and how commands like date, netstat, and many others wrok with cron.
But my main question still remains, although in different terms:
if commands like mozilla, xclock, lmule (and any program which uses the X server, I assume) need a display variable set in order to work from cron, my questions are now
what variable(s) do I need to change if I want lmule to work from cron? (did you mean the DISPLAY variable?)
what value must I give to this (these) variable(s)?
I'm specially interested in the case of lmule, but I don't know if the answer is general or specifc to the command.
I think a much better question would be
where or how can I find out which variable(s) do I need and what values?

regards.

Y0jiMb0 08-20-2003 01:44 AM

I finally could run lmule (or xclock or mozilla or any application using graphics(?) ) from crond. It was a stupid error, like it uses to be!

I'm going to explain what I did. Maybe this can help to anyone...

I checked the DISPLAY variable and I found

DISPLAY=:0.0

as it must be, because I've always been able to run lmule, xclock, mozilla and others under konsole, and this is exactly the point: it was under konsole, but (I think) crond knows nothing about konsole so If one switchs, for example, to tty1 (ctrl+alt+F1) and checks the set command, one should find DISPLAY=:0.0 in order to be able to run such graphical applications from crond; if not, one can write a small script (for instance '/home/pq/mozill.cron.sh') with

export DISPLAY=:0.0
/usr/bin/mozilla

and afterwards do

crontab -e

and write there

23 0 * * * /home/pq/mozill.cron.sh

With this, one can (at least I could) run mozilla from crond (in the example it starts every day 23 minutes after midnight)

regards :)


All times are GMT -5. The time now is 08:38 PM.