Join the community today
Become a Member

Why is it bad directly editing /var/spool/cron/root ?

Discussion in 'System Administration' started by rdan, Sep 16, 2019.

  1. rdan

    rdan Well-Known Member

    5,439
    1,397
    113
    May 25, 2014
    Ratings:
    +2,186
    Local Time:
    9:04 PM
    Mainline
    10.2
    As you mention on the other thread, but I always do this when adding my rsync cron with very long arguments/options.

     
  2. eva2000

    eva2000 Administrator Staff Member

    53,178
    12,112
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,647
    Local Time:
    11:04 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Biggest issue is you can end up deleting or wiping your /var/spool/cron/root file by accident if manual editing is done incorrectly !

    crontab -e has syntax error checking while editing file manually wouldn't also see https://serverfault.com/a/347321/34814 and https://ubuntuforums.org/showthread.php?t=2173811

    manual edits can also get overwritten by crontab -e edit activity too
    proper way to edit or insert cronjobs is either crontab -e or use cronjob -l to list cronjobs piped into a text file and then edit that text file and then use crontab text file to re-register and reimport the edited list of cronjobs via crontab command
    Code (Text):
    # save all cronjobs by root user into listofcronjobs.txt text file (serves as backup too)
    crontab -l > listofcronjobs.txt
    # then edit listofcronjobs.txt
    # then reload edited listofcronjobs.txt
    crontab listofcronjobs.txt
    

    That is how centmin mod's automated routines add cronjobs :)
     
  3. rdan

    rdan Well-Known Member

    5,439
    1,397
    113
    May 25, 2014
    Ratings:
    +2,186
    Local Time:
    9:04 PM
    Mainline
    10.2
    Thanks for the new lesson Eva :).
     
  4. rdan

    rdan Well-Known Member

    5,439
    1,397
    113
    May 25, 2014
    Ratings:
    +2,186
    Local Time:
    9:04 PM
    Mainline
    10.2
    That is a very nice steps Eva.
    I'll take note this for my upcoming servers.
     
  5. jacknguyen

    jacknguyen Member

    39
    6
    8
    Jun 3, 2022
    Ratings:
    +9
    Local Time:
    9:04 PM
    1.5
    10
    I found the easy way to edit the cronjobs for newbie like me.
    Code:
    crontab -l > listcron
    echo "* * * * * /cron.../.... " >> listcron
    then
    crontab listcron