LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   admin stupidity: crontab (https://www.linuxquestions.org/questions/linux-newbie-8/admin-stupidity-crontab-4175646582/)

alabamatoy 01-20-2019 07:55 AM

admin stupidity: crontab
 
I inadvertently hit return after entering crontab, and now all my cron scheduled stuff is gone.

I have a backup tar, but I cannot seem to extract the correct file (/etc/crontab) from it.

What am I doing wrong? Is /etc/crontab the correct file to restore? Or is it somewhere else?

Any help would really be appreciated. A painful lesson has been learned!

Corvette 01-20-2019 08:10 AM

The file should be located under "/var/spool/cron/crontabs/USERNAME".

alabamatoy 01-20-2019 08:12 AM

Now I am really worried...
Code:

tar -t -v -f '/media/WD_USB/Signal_Security_bkp_Tue_Jan_15_ 2_16_32' -p /etc/crontab
V--------- 0/0              0 2019-01-15 02:16 20180203--Volume Header--
tar: /etc/crontab: Not found in archive
tar: Exiting with failure status due to previous errors

This was created with a backup of directory "/", why would /etc/crontab not be in there?

Corvette 01-20-2019 08:20 AM

Forgive my ignorance, but what is "-p" argument for? Maybe try something like this:
PHP Code:

tar -tvf myarchive.tar.gz '*crontab*' 

. How are you performing a backup? Are you sure it is being performed recursively?

michaelk 01-20-2019 08:39 AM

There are users crontab and system crontab files. As posted depending on distribution users crontab files including roots are saved in /var/spool/cron/crontabs/username. System crontab files are saved in /etc/crontab, /etc/cron.daily, /etc/cron.weekly, /etc/cron.hourly, /etc/cron.monthly.

Without knowing how your backup was created we can not say why /etc/crontab is missing. However, crontab is not used for system cron jobs so /etc/crontab should still be intact. Were you logged in as root or other user when you inadvertently hit return? Did root or that user actually have a crontab?

crontab will use stdin for inputs if you just press return but normally pressing ctrl-c will cancel.

alabamatoy 01-20-2019 09:03 AM

Quote:

Originally Posted by Corvette (Post 5951304)
The file should be located under "/var/spool/cron/crontabs/USERNAME".

Well, its root's crontab that I dorked up.

Apparently, part of my problem is "/etc/crontab" versus "etc/crontab"

Still trying...and learning....

rknichols 01-20-2019 09:05 AM

tar normally strips off the leading "/" from paths, so "/etc/crontab" would be in the archive as "etc/crontab". But as others have pointed out, that is not the file you were replacing with the crontab command. You can check easily enough by looking at the current content of /etc/crontab.

Corvette 01-20-2019 10:02 AM

Quote:

Originally Posted by alabamatoy (Post 5951319)
Well, its root's crontab that I dorked up.

Apparently, part of my problem is "/etc/crontab" versus "etc/crontab"

Still trying...and learning....

If you edited the root users crontab (that is, using crontab -e while logged in as root), you would still find it underneath the /var/spool/cron/crontabs directory. If you are referring to a system job (not the root user's crontab), your files might be underneath /etc/cron.d, /etc/cron.daily, etc, although /var Something I should have clarified earlier, what distro are you using? My responses have been from the perspective of a Debian based distro.

alabamatoy 01-20-2019 10:47 AM

Quote:

Originally Posted by Corvette (Post 5951308)
Forgive my ignorance, but what is "-p" argument for?

Its explicitly setting a pattern to search for. I didnt now it would work w/o it.

Quote:

Originally Posted by rknichols (Post 5951321)
tar normally strips off the leading "/" from paths, so "/etc/crontab" would be in the archive as "etc/crontab". But as others have pointed out, that is not the file you were replacing with the crontab command. You can check easily enough by looking at the current content of /etc/crontab.

OK, of course yall are right. The crontab file in the backup archive is exactly the same timestamp and filesize as the one currently in /etc/

So I looked for the root crontab, and its there, or seems to be...but I cant seem to extract it.

Code:

# tar -t -v -f '/media/WD_USB/Signal_Security_bkp_Tue_Jan_15_ 2_16_32' -p 'var/spool/cron/crontabs/root'
V--------- 0/0              0 2019-01-15 02:16 20180203--Volume Header--
-rw------- root/crontab  1123 2019-01-09 08:12 var/spool/cron/crontabs/root

# tar --extract --file="var/spool/cron/crontabs/root" '/media/WD_USB/Signal_Security_bkp_Tue_Jan_15_ 2_16_32'
tar: var/spool/cron/crontabs/root: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

Now what?

alabamatoy 01-20-2019 10:49 AM

Quote:

Originally Posted by Corvette (Post 5951336)
Something I should have clarified earlier, what distro are you using? My responses have been from the perspective of a Debian based distro.

Indeed, my bad...Ubuntu 16.04

Corvette 01-20-2019 10:51 AM

I think you got your order of arguments wrong. It should be "tar -xf myarchive.tar.gz /var/spool/cron/crontabs/root".

The following is a good resource on the topic: https://www.cyberciti.biz/faq/linux-...pecific-files/.

alabamatoy 01-20-2019 11:29 AM

Thank you all! My cron tasks are all back! HOOOOaah!!!

I have learned several valuable lessons from this. Your patience with the newb is much appreciated.


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