Welcome to Centmin Mod Community
Register Now

Sysadmin strange cancellation of the cron

Discussion in 'System Administration' started by upgrade81, Feb 22, 2018.

  1. upgrade81

    upgrade81 Member

    296
    17
    18
    Sep 5, 2016
    CH
    Ratings:
    +30
    Local Time:
    8:33 AM
    1.17
    10.3
    I noticed that the crons have been completely erased, using the usual command crontab -e is completely empty.
    On the contrary, it opens a temporary file. example: crontab.dry6go

    How could it have happened?
    Can they recover?

     
  2. Sunka

    Sunka Well-Known Member

    1,150
    325
    83
    Oct 31, 2015
    Pula, Croatia
    Ratings:
    +525
    Local Time:
    8:33 AM
    Nginx 1.17.9
    MariaDB 10.3.22
    That it happened to me once, for no reason.
    I ended up with manually save crontab lists into file so if that glitch show up again, I just copy/paste crons.

    Also, I add cron to make a copy of all important files every day and rsync them to another server. Just in case
     
  3. upgrade81

    upgrade81 Member

    296
    17
    18
    Sep 5, 2016
    CH
    Ratings:
    +30
    Local Time:
    8:33 AM
    1.17
    10.3
    I was thinking of doing the same

    curiosity do you have a quick list of directories to copy?

    I was thinking of using rsync.net with a Swiss location.
     
  4. eva2000

    eva2000 Administrator Staff Member

    58,905
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    4:33 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    any output for
    Code (Text):
    crontab -l
    

    and output for
    Code (Text):
    service crond status
    

    any contents in /var/spool/cron/root too ?
    Code (Text):
    cat /var/spool/cron/root
    

    wrap in CODE bbcode tags

    any clues in your command history filter grepped on crontab ? maybe you ran some command incorrectly ?
    Code (Text):
    history | grep crontab
    


    if they are gone, you can sort of reconstruct the cronjobs from the cronjob log that logs each cronjob run sort of

    last 200 lines of the log with egrep -v filter to exclude some system related cronjobs
    Code (Text):
    egrep -v 'anacron|cron.daily|cron.hourly|sa\/sa[1,2]|pam_|csf|sysstat|LIST' /var/log/cron | tail -200
    

    note some are system cronjobs listed via hostname and some are root user ones

    For even more filtered list returning just last 2 columns of cron log which is usually the crontab line in brackets
    Code (Text):
    egrep -v 'anacron|cron.daily|cron.hourly|sa\/sa[1,2]|pam_|csf|sysstat|LIST' /var/log/cron | awk '{print $8,$9}' | sort -u
    

    example
    Code (Text):
    egrep -v 'anacron|cron.daily|cron.hourly|sa\/sa[1,2]|pam_|csf|sysstat|LIST' /var/log/cron | awk '{print $8,$9}' | sort -u
    (/usr/bin/cminfo_updater 2>/dev/null)
    (/usr/local/src/centminmod/tools/autoprotect.sh 2>/dev/null)
    

    correspond with default centmin mod cronjobs
    Code (Text):
    crontab -l
    11 */23 * * * /usr/local/src/centminmod/tools/autoprotect.sh 2>/dev/null
    0 */4 * * * /usr/bin/cminfo_updater 2>/dev/null
    


    Or filter cron log to display time too
    Code (Text):
    egrep -v 'anacron|cron.daily|cron.hourly|sa\/sa[1,2]|pam_|csf|sysstat|LIST' /var/log/cron | awk '{print $1,$2,$3,$8,$9}'
    

    Code (Text):
    egrep -v 'anacron|cron.daily|cron.hourly|sa\/sa[1,2]|pam_|csf|sysstat|LIST' /var/log/cron | awk '{print $1,$2,$3,$8,$9}'
    Feb 19 04:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 19 08:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 19 12:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 19 16:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 19 20:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 19 23:11:01 (/usr/local/src/centminmod/tools/autoprotect.sh 2>/dev/null)
    Feb 20 00:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 20 00:11:01 (/usr/local/src/centminmod/tools/autoprotect.sh 2>/dev/null)
    Feb 20 04:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 20 08:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 20 12:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 20 16:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 20 20:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 20 23:11:02 (/usr/local/src/centminmod/tools/autoprotect.sh 2>/dev/null)
    Feb 21 00:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 21 00:11:01 (/usr/local/src/centminmod/tools/autoprotect.sh 2>/dev/null)
    Feb 21 04:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 21 08:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 21 12:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 21 16:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    Feb 21 20:00:01 (/usr/bin/cminfo_updater 2>/dev/null)
    
     
  5. eva2000

    eva2000 Administrator Staff Member

    58,905
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    4:33 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
  6. Sunka

    Sunka Well-Known Member

    1,150
    325
    83
    Oct 31, 2015
    Pula, Croatia
    Ratings:
    +525
    Local Time:
    8:33 AM
    Nginx 1.17.9
    MariaDB 10.3.22
    It is relative.
    I make a copy of this files everyday and rsync (and save last 7 copies) to another server just in case.

    This is my script which is ran every morning and after that rsync take it

    Code:
    #!/bin/bash
    /bin/cp /etc/logrotate.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/lib/php.ini /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/my.cnf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/redis.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/redis-sentinel.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/centminmod/custom_config.inc /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/centminmod/php.d/zendopcache.ini /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/centminmod/php.d/zzz_customphp.ini /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/csf/csf.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/elasticsearch/elasticsearch.yml /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/logwatch/conf/logwatch.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/etc/php-fpm.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/nginx.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/php.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/drop.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/staticfiles.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/conf.d/virtual.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/conf.d/ssl.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/conf.d/pijanitvor.com.ssl.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/brotli_inc.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/maintenance.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
     
  7. Matt

    Matt Well-Known Member

    932
    415
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +671
    Local Time:
    7:33 AM
    1.5.15
    MariaDB 10.2
    Running
    Code:
    crontab -r
    accidentally will wipe the contents of the crontab

    Check your bash history to see if you made a mistake (having the e and r buttons next to each other isn't ideal in this case!)
     
  8. eva2000

    eva2000 Administrator Staff Member

    58,905
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    4:33 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Yeah indeed. Haven't looked into whether you could re-assign the -r flag. Though in 18+ yrs never made that mistake ! Guess part of is luck :)
     
  9. eva2000

    eva2000 Administrator Staff Member

    58,905
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    4:33 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Ok just answered my own question from here
    Code (Text):
    crontab -r
    "r" not allowed
    

    I don't even recall the last time i used crontab -r deliberately. Disabling the command might make sense in Centmin Mod ?
     
  10. pamamolf

    pamamolf Well-Known Member

    4,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    9:33 AM
    Nginx-1.29.x
    MariaDB 10.6.x
    Why not :)

    I think it will be good to not allowed to run that command...
     
  11. upgrade81

    upgrade81 Member

    296
    17
    18
    Sep 5, 2016
    CH
    Ratings:
    +30
    Local Time:
    8:33 AM
    1.17
    10.3
    Thank you all for the precious information.

    Now I rebuilt the crons were not many.

    and Yes, thanks to the @eva2000 command
    Code (Text):
    history | grep crontab


    I mistakenly launched crontab -r :cry:

    I would say that it is good and right to disable this useless option.
     
  12. Matt

    Matt Well-Known Member

    932
    415
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +671
    Local Time:
    7:33 AM
    1.5.15
    MariaDB 10.2
    I've done it once before as well myself :(
     
  13. eva2000

    eva2000 Administrator Staff Member

    58,905
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    4:33 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+