1847356 Members
4534 Online
110264 Solutions
New Discussion

cron jobs - help needed

 
Anand_30
Regular Advisor

cron jobs - help needed

Hi,

I have scheduled a script using crontab. I used the command crontab cron.txt where the cron.txt file included the sceduling details.
But after doing this when I viewed the scheduled jobs using "crontab -e", I noticed that only the job which i scheduled recently is available and all the other scheduled jobs are missing.

Did I delete all the other scheduled jobs in my server. In that case is there any way to revert back all the other scheduled jobs.

Can anyone please help out in this problem. I will be in deep trouble if I have accidentally deleted all the scheduled jobs.

Thanks,
Anand
9 REPLIES 9
RAC_1
Honored Contributor

Re: cron jobs - help needed

The procedure is as follows.

crontab -l user > /tmp/text_file
vi /tmptext_file
do your changes and save.

and crontab /tmp/text_file

you have lost your contab. check if you had ever taken backup of your crontab. /var/adm/cron/crontabs

Anil
There is no substitute to HARDWORK
Robert-Jan Goossens
Honored Contributor

Re: cron jobs - help needed

Hi Anand,

Looks like you will need to restore the /var/spool/cron/crontabs/root file from backup.

Regards,
Robert-Jan
hari jayaram_1
Frequent Advisor

Re: cron jobs - help needed

Anand,

does the cron.txt include all the previous cron jobs.

As what user did you do the command.

could you please also give the exact command you executed.
Rita C Workman
Honored Contributor

Re: cron jobs - help needed

hmm...why don't you cd to /var/spool/cron/crontab and see what files you see.

To bring up the active cronfile that you as the user have out there you could simply have typed:

crontab -e

And then edited the file and saved it, thus making it active for the scheduled jobs mentioned within.

Try going out to /var/spool/cron/crontabs and see if there is an old cron.txt file there. It is possible you may have this cron.txt file existing in multiple places and only one of them is going to be run...

Just a thought,
Rita
SS_6
Valued Contributor

Re: cron jobs - help needed

you have overwritten your crontab entries with new one. Restore it from backup or ignite make_recovery tape. for new user you have to do like this.
#crontab -e user
By providing solutions I am helping myself
Dani Seely
Valued Contributor

Re: cron jobs - help needed

Hello Anand,
Good news, bad news -

Bad news, the only crontab that was affected (accidentally deleted) is the crontab for the user you were logged in as.

Good news, if another user on the system has the same requirements and may have the same crontab, you can make a copy of that user's crontab and submit that crontab for the user that was affected.

To safely edit the crontab file you can either perform a 'crontab -e' and edit the file and re-submit after making the changes or the safer method is to dump your crontab to a file, make the changes in the file, then submit the file back to cron ... and if you are worried about security, ensure the permissions are strong on the file you dumped and edited, or just remove it after you've submitted the update to cron AND verified the new crontab has been updated. Sample of this is 'crontab >crontab.bak'

The above method can be used to restore your affected users' crontab by making a backup of another users' crontab, ensure the permissions are loose enough that the affected user can view and make changes, then su to your affected user, view and make the changes and then submit them back to cron 'crontab
That should do it. Hope you have another user that has a similar crontab. If you don't, hope you have a good backup of the /var/spool/cron/crontabs files. Hope this helps. Good luck!
Together We Stand!
Dani Seely
Valued Contributor

Re: cron jobs - help needed

I hit submit rather than preview, went back and realized I had a typo in the sample ... to perform a crontab backup, use 'crontab -l >crontab.bak'
Together We Stand!
lawrenzo
Trusted Contributor

Re: cron jobs - help needed

here is a similar way to edit cron:

crontab -l > mycrontab
vi mycrontab

once changes are made:

crontab mycrontab

this is apperently the safest and recomended way.

You can copy another user's cron but if there entries were not the same then the deleted file will not match your original cron - do you backup?
hello
Sanjay_6
Honored Contributor

Re: cron jobs - help needed

Hi,

Crontab some_file will replace the existing cron job with the jobs listed in the file given in the command line, in this case some_file.

It is difficult to get the previous list of cron jobs if you don't have a backup copy. Restore it from the backup id possible.

Hope this helps.

Regds