1849466 Members
5745 Online
104044 Solutions
New Discussion

CRON

 
Nobody's Hero
Valued Contributor

CRON

Can someone tell me how to restore the root crontab?
UNIX IS GOOD
8 REPLIES 8
harry d brown jr
Honored Contributor

Re: CRON

From a backup, or manually recreate it, then issue (as root)

crontab filename

Of course, restart cron

live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: CRON

From your backup, or another "like" system, restore/copy

/var/spool/cron/ and all of its subdirectories.

live free or die
harry
Live Free or Die
Sanjay_6
Honored Contributor

Re: CRON

Hi Robert,

You can create a new crontab file for root. Or restore it from the backup. The filename is /usr/spool/cron/crontabs/root

Hope this helps.

Regds
Paula J Frazer-Campbell
Honored Contributor

Re: CRON

Hi

Make a habit of copying the crontab to an other location.

If fact let cron do it for you every night.


Paula
If you can spell SysAdmin then you is one - anon
Eileen Millen
Trusted Contributor

Re: CRON

after you get the file back, you should keep it in roots home directory
you can update the file with changes and enter
crontab filename
to submit it as a cronjob.
Eileen
Michael Tully
Honored Contributor

Re: CRON

Hi,

There are a few ways to avoid this happening where cron files get removed.
Always keep a copy on the system(whether in 'root's home directory or somewhere else)
Never use crontab -e to edit the cron file.
Always use 'crontab -l >/tmp/mycron' , edit the file and submit it 'crontab /tmp/mycron', that way there is always a file on hand.
We use 'rcs' for any changes to crontab, that way we always have a copy and all changes that have been made.

My 2 cents worth
Anyone for a Mutiny ?
Hell.Leader
Occasional Advisor

Re: CRON

Restore "/usr/spool/cron/crontabs/root" file from your backup.
Then use "#crontab root".
HPcert
Frank Slootweg
Honored Contributor

Re: CRON

It has already been *implied* by Harry, Eileen, Michael and Hell.Leader (Did I forget anybody?), but you *must* install the restored crontab with the crontab(1) command!

I.e. you first restore the file from somewhere (probably from the /var/spool/cron/crontabs/root file on your backup media), then *copy* the file somewhere, let's say to /crontab.root and then issue the crontab(1) command:

# crontab /crontab.root

The reason for this is that cron(1M) only reads the 'spool' copy (/var/spool/cron/crontabs/root) when it starts, i.e. normally at system boot. The file is *not* re-read unless crontab(1) tells cron(1M) to do so, so if you do not use crontab(1), cron(1M) may/will never run the jobs listed in the 'spool' copy.