MoonPoint Support Logo

 


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
November
Sun Mon Tue Wed Thu Fri Sat
           
6
           
2014
Months
Nov


Thu, Nov 06, 2014 10:26 pm

Copying the crontab file from a backup

On a CentOS Linux system, I needed to copy the crontab file for the root account from a backup disk. The crontab files are stored in /var/spool/cron, so I needed the /var/spool/cron/root for the root account. Since I didn't want to include every line from the old crontab file, I edited the old one and copied its contents. I then used crontab -e while logged into the root account to create a new crontab file. I pasted the contents of the old file into the new one. When I tried saving the file, I got the message below:
# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
"/tmp/crontab.wpnAYC":3: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit?

I had also seen "bad day-of-week", instead of "bad minute" when editing the file previously. I typed "y" to retry and then realized the source of the problem, which I thought at first from the error message was some error in the first five entries on the line that specify when a cron job should run. Instead, the problem was because when I copied and pasted the contents of the old file into the new file, entries that had wrapped around to a new line on the screen were now on two lines whereas before they were only on one line. E.g., for the output above, line 3, which was the one referenced for "bad minute" was really the continuation of line 2, but it was now, because of my copy and paste operation, on line 3 with no time specified, but instead the end part of the command line. I edited those lines where that had occurred, so though they wrapped around on the screen each entry was one continuous line. I was then able to save the file successfully and then view the crontab file with crontab -l Since I had SELinux enabled on the system, I checked the security context for the cron file and saw the following.

# ls -Z /var/spool/cron/root
-rw-------. root root unconfined_u:object_r:user_cron_spool_t:s0 /var/spool/cron/root

References:

  1. Cron
    Wikipedia, The Free Encyclopedia
  2. Cron and Crontab usage and examples
    Date: May 4, 2014
    Pantz.org Technical Reference Site
  3. How to Backup Crontabs of All Users on CentOS, RHEL, Ubuntu & Dabian
    By: Rahul Kumar
    Date: April 2, 2014
    TecAdmin.net

[/os/unix/linux/centos] permanent link

Once You Know, You Newegg AliExpress by Alibaba.com

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo