Join the community today
Register Now

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

    4,962
    1,183
    113
    May 25, 2014
    Ratings:
    +1,797
    Local Time:
    10:32 AM
    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

    44,731
    10,196
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,804
    Local Time:
    12:32 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    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

    4,962
    1,183
    113
    May 25, 2014
    Ratings:
    +1,797
    Local Time:
    10:32 AM
    Mainline
    10.2
    Thanks for the new lesson Eva :).
     
  4. rdan

    rdan Well-Known Member

    4,962
    1,183
    113
    May 25, 2014
    Ratings:
    +1,797
    Local Time:
    10:32 AM
    Mainline
    10.2
    That is a very nice steps Eva.
    I'll take note this for my upcoming servers.