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!


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