Want to subscribe to topics you're interested in?
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,419
    1,386
    113
    May 25, 2014
    Ratings:
    +2,167
    Local Time:
    3:17 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

    50,472
    11,661
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,083
    Local Time:
    5:17 AM
    Nginx 1.25.x
    MariaDB 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

    5,419
    1,386
    113
    May 25, 2014
    Ratings:
    +2,167
    Local Time:
    3:17 AM
    Mainline
    10.2
    Thanks for the new lesson Eva :).
     
  4. rdan

    rdan Well-Known Member

    5,419
    1,386
    113
    May 25, 2014
    Ratings:
    +2,167
    Local Time:
    3:17 AM
    Mainline
    10.2
    That is a very nice steps Eva.
    I'll take note this for my upcoming servers.
     
  5. jacknguyen

    jacknguyen New Member

    24
    4
    3
    Jun 3, 2022
    Ratings:
    +7
    Local Time:
    3:17 AM
    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