Welcome to Centmin Mod Community
Become a Member

Cron command not working - (maybe Centminmod filters it)

Discussion in 'System Administration' started by pamamolf, Mar 30, 2015.

  1. pamamolf

    pamamolf Well-Known Member

    4,003
    420
    83
    May 31, 2014
    Ratings:
    +812
    Local Time:
    7:16 AM
    Nginx-1.17.x
    MariaDB 10.3.x
    Hi
    I am using this command as a cron to clean old backups:

    Code:
    /usr/bin/find /backup/ -type d -mtime +1 -print0 | /usr/bin/xargs -0 /bin/rm -rf
    When i run it from ssh it works but not on cron :(

    My cron:
    Code:
    55 5 * * * /usr/bin/find /backup/ -type d -mtime +1 -print0 | /usr/bin/xargs -0 /bin/rm -rf
    Cron log:

    Code:
    Mar 30 05:55:01 server CROND[9526]: (root) CMD (/usr/bin/find /backup/ -type d -mtime +1 -print0 | xargs -0 rm -rf)
    But after that i can see a folder with files there from Mar 28..

    Any ideas?


    Thanks
     
  2. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,486
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,838
    Local Time:
    3:16 PM
    Nginx 1.21.x
    MariaDB 10.x
    set it up in bash shell script with .sh extension and run script in cron
     
  3. pamamolf

    pamamolf Well-Known Member

    4,003
    420
    83
    May 31, 2014
    Ratings:
    +812
    Local Time:
    7:16 AM
    Nginx-1.17.x
    MariaDB 10.3.x
    I did it but is not working :(

    log:

    Code:
    Mar 30 14:45:01 server CROND[5828]: (root) CMD (/scriptb/cleanbackups.sh)
    My cron:

    Code:
    45 14 * * * /scriptb/cleanbackups.sh
    And my file cleanbackups.sh :
    Code:
    #!/bin/bash
    /usr/bin/find /backup/ -type d -mtime +1 -print0 | /usr/bin/xargs -0 /bin/rm -rf
    
    And yes i chmod +x the file...
     
  4. pamamolf

    pamamolf Well-Known Member

    4,003
    420
    83
    May 31, 2014
    Ratings:
    +812
    Local Time:
    7:16 AM
    Nginx-1.17.x
    MariaDB 10.3.x
    What a crazy thing is this?

    It seems to run every 2 days ? as i sleep and then wake up an it was ok now the old folder missing with the old files inside....
     
  5. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,486
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,838
    Local Time:
    3:16 PM
    Nginx 1.21.x
    MariaDB 10.x
    -mtime +1 means every 48hrs
    -mtime +0 means every 24hrs

    google search ;)
     
  6. pamamolf

    pamamolf Well-Known Member

    4,003
    420
    83
    May 31, 2014
    Ratings:
    +812
    Local Time:
    7:16 AM
    Nginx-1.17.x
    MariaDB 10.3.x
    I thought that -mtime +1 means to delete folder older than 1 day .....