LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-20-2019, 07:55 AM   #1
alabamatoy
LQ Newbie
 
Registered: Jan 2019
Posts: 7

Rep: Reputation: Disabled
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!
 
Old 01-20-2019, 08:10 AM   #2
Corvette
Member
 
Registered: Jul 2017
Location: Missouri, United States
Distribution: Debian 9
Posts: 110

Rep: Reputation: 24
The file should be located under "/var/spool/cron/crontabs/USERNAME".
 
Old 01-20-2019, 08:12 AM   #3
alabamatoy
LQ Newbie
 
Registered: Jan 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
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?
 
Old 01-20-2019, 08:20 AM   #4
Corvette
Member
 
Registered: Jul 2017
Location: Missouri, United States
Distribution: Debian 9
Posts: 110

Rep: Reputation: 24
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?
 
Old 01-20-2019, 08:39 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
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.

Last edited by michaelk; 01-20-2019 at 08:41 AM.
 
Old 01-20-2019, 09:03 AM   #6
alabamatoy
LQ Newbie
 
Registered: Jan 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Corvette View Post
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....
 
Old 01-20-2019, 09:05 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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.
 
Old 01-20-2019, 10:02 AM   #8
Corvette
Member
 
Registered: Jul 2017
Location: Missouri, United States
Distribution: Debian 9
Posts: 110

Rep: Reputation: 24
Quote:
Originally Posted by alabamatoy View Post
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.

Last edited by Corvette; 01-20-2019 at 10:03 AM.
 
Old 01-20-2019, 10:47 AM   #9
alabamatoy
LQ Newbie
 
Registered: Jan 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Corvette View Post
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 View Post
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?
 
Old 01-20-2019, 10:49 AM   #10
alabamatoy
LQ Newbie
 
Registered: Jan 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Corvette View Post
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
 
Old 01-20-2019, 10:51 AM   #11
Corvette
Member
 
Registered: Jul 2017
Location: Missouri, United States
Distribution: Debian 9
Posts: 110

Rep: Reputation: 24
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/.
 
Old 01-20-2019, 11:29 AM   #12
alabamatoy
LQ Newbie
 
Registered: Jan 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php DSO stupidity Kilka *BSD 5 01-08-2004 03:30 PM
Win98+Linux. Help me determine my stupidity level! J_Szucs General 14 12-07-2003 10:35 PM
GRUB toasted, can't boot SuSE 8.2 after partition stupidity shock_ez Linux - Newbie 2 11-03-2003 09:42 AM
Black screen at start from own stupidity kaega2 Linux - Software 5 09-27-2003 12:43 AM
Root password and stupidity donblas Slackware 4 03-12-2003 03:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration