Join the community today
Register Now

Cron command not working - (maybe Centminmod filters it)

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

  1. pamamolf

    pamamolf Well-Known Member

    2,529
    231
    63
    May 31, 2014
    Ratings:
    +394
    Local Time:
    12:41 AM
    Nginx-1.13.x
    MariaDB 10.1.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

    29,031
    6,588
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,780
    Local Time:
    7:41 AM
    Nginx 1.13.x
    MariaDB 5.5
    set it up in bash shell script with .sh extension and run script in cron
     
  3. pamamolf

    pamamolf Well-Known Member

    2,529
    231
    63
    May 31, 2014
    Ratings:
    +394
    Local Time:
    12:41 AM
    Nginx-1.13.x
    MariaDB 10.1.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

    2,529
    231
    63
    May 31, 2014
    Ratings:
    +394
    Local Time:
    12:41 AM
    Nginx-1.13.x
    MariaDB 10.1.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

    29,031
    6,588
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,780
    Local Time:
    7:41 AM
    Nginx 1.13.x
    MariaDB 5.5
    -mtime +1 means every 48hrs
    -mtime +0 means every 24hrs

    google search ;)
     
  6. pamamolf

    pamamolf Well-Known Member

    2,529
    231
    63
    May 31, 2014
    Ratings:
    +394
    Local Time:
    12:41 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    I thought that -mtime +1 means to delete folder older than 1 day .....