1836547 Members
2696 Online
110102 Solutions
New Discussion

Re: cron problem

 
Bill Brutzman
Frequent Advisor

cron problem

Last night, the rights of many files was changed. I suspect a bad cron process and I need help tracking it down.

First I did a crontab -l to list the crons. I did not see anything obvious.

Then I made the mistake of just running 'crontab' by itself. It came back with a blank line. I hit twice and then did not know how to get out of it.

I closed the terminal emulator session [IBM's Dynamic Connect] by simply closing the Windows window via in the upper right corner.

Now when I try a crontab -l, I get a message indicating "crontab: crontab can't open your crontab file".

Help would be appreciated.

Regards,

Bill

8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: cron problem

Hi Bill:

Oops, you created an empty crontab file!

I assume you have a backup, so, restore '/var/spool/cron/crontabs/' appropriately.

Regards!

...JRF...
Mark Vollmers
Esteemed Contributor

Re: cron problem

Hi, Bill. First off, if you just type in crontab, hitting a crtl-C will exit out. Not that that helps you now. If you have a tape backup, I would go grab the old version of /etc/crontab and restore it. Check it to make sure that it is correct, and use crontab -e to edit. As to the file changing, you could take a look at all the process' that are being called and make sure that none of these have been changed. If you only have a few items in the crontab, you could also just delete the old one and re-create it.

Mark
"We apologize for the inconvience" -God's last message to all creation, from Douglas Adams "So Long and Thanks for all the Fish"
someone_4
Honored Contributor

Re: cron problem

Hey Mr. James ..
just wondering what created the empty cron file? Hitting twice and exiting with the x?

Richard
Rita C Workman
Honored Contributor

Re: cron problem

When you used crontab without a filename it created a blank file. Checkout the manpage on crontab and you will see this explained.
So basically, what James said above is exactly what happened. You ran the crontab command without a file and in effect overwrote your existing file and cron'd it with a blank file.
You can restore from a backup tape...and what I do as a real quick fix is make a backup (root.bak) of the file in /var/spool/crontabs
Because I always do things like this when I'm doing a quick fix and heading out the door. So I want to restore fast....

Just a thought,
Rit
James R. Ferguson
Acclaimed Contributor

Re: cron problem

Hi Bill and Richard:

Richard, I can reproduce Bill's problem. Actually the crontab file isn't emptied but removed.

Note what the man pages for 'crontab' say:

/begin_quote/

crontab [file] Create or replace your crontab file by copying the specified file, or standard input if file is omitted or - is specified as file, into the crontab directory, /var/spool/cron/crontabs.

/end_quote/

# crontab -l

...will echo nothing if a truly empty file exists. whereas a missing file returns:

"crontab: can't open your crontab file."

Regards!

...JRF...
someone_4
Honored Contributor

Re: cron problem

I was able to reproduce that =)
First I made a root.bk and a root.bk1
then i cleared everything oout of root.bk1.
I ran the command
crontab root.bk1
checked crontab and guess what? It was empty,
crontab -l
returns nothing
crontab -e lets me edit the file.
Delete root ..
crontab -l
crontab: can't open your crontab file.
why .. because there is no file to open!
crontab root.bk
restores theback up file like rita mentioned.
The only thing I couldnt do was remove the crontab file by just doing
#crontab
other wise ..I did learn a little about crontab .. =)

Richard
Bill Hassell
Honored Contributor

Re: cron problem

Because crontab is a bit unforgiving, most sysadmins will NEVER use crontab -e, but instead will make a local copy of the crontab file in root's $HOME. All changes are made to that file, then crontab file_name is run to install the new file.

Now, if a mistake is made, the crontab entries are restored by simply running crontab file_name again.


Bill Hassell, sysadmin
Michael Tully
Honored Contributor

Re: cron problem

The last time I saw something like this
occur was with a Junior, who was already told
never ever use 'crontab -e'
I *ALWAYS* use the habit of
# crontab -l > /tmp/wrk
# vi /tmp/wrk
make my changes
# crontab /tmp/wrk (to submit)

Guess what the Junior was instructed to
find the backup tape(s) after looking as
red as a tomato!

-Michael
Anyone for a Mutiny ?