Welcome to Centmin Mod Community
Become a Member

Sysadmin strange cancellation of the cron

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

  1. upgrade81

    upgrade81 Premium Member Premium Member

    133
    6
    18
    Sep 5, 2016
    Italy
    Ratings:
    +8
    Local Time:
    5:35 AM
    1.13.8
    10
    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,003
    276
    83
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +453
    Local Time:
    5:35 AM
    Nginx 1.15.0
    MariaDB 10.2.15
    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
     
    • Like Like x 1
  3. upgrade81

    upgrade81 Premium Member Premium Member

    133
    6
    18
    Sep 5, 2016
    Italy
    Ratings:
    +8
    Local Time:
    5:35 AM
    1.13.8
    10
    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

    36,040
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    1:35 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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

    36,040
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    1:35 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    • Like Like x 1
  6. Sunka

    Sunka Well-Known Member

    1,003
    276
    83
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +453
    Local Time:
    5:35 AM
    Nginx 1.15.0
    MariaDB 10.2.15
    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
     
    • Informative Informative x 1
  7. Matt

    Matt Moderator Staff Member

    765
    343
    63
    May 25, 2014
    Sheffield, UK
    Ratings:
    +512
    Local Time:
    4:35 AM
    1.7.1
    MariaDB 10
    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!)
     
    • Agree Agree x 3
    • Winner Winner x 1
  8. eva2000

    eva2000 Administrator Staff Member

    36,040
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    1:35 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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

    36,040
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    1:35 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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

    3,113
    295
    83
    May 31, 2014
    Ratings:
    +530
    Local Time:
    6:35 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    Why not :)

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

    upgrade81 Premium Member Premium Member

    133
    6
    18
    Sep 5, 2016
    Italy
    Ratings:
    +8
    Local Time:
    5:35 AM
    1.13.8
    10
    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.
     
    • Like Like x 1
  12. Matt

    Matt Moderator Staff Member

    765
    343
    63
    May 25, 2014
    Sheffield, UK
    Ratings:
    +512
    Local Time:
    4:35 AM
    1.7.1
    MariaDB 10
    I've done it once before as well myself :(
     
  13. eva2000

    eva2000 Administrator Staff Member

    36,040
    7,906
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,188
    Local Time:
    1:35 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    • Like Like x 1
    • Winner Winner x 1
    • Friendly Friendly x 1
..