crontab not working under arch linux

Tag: linux , bash , find , crontab Author: zhoufm230027 Date: 2014-04-01

I tried to set up a schedule to remove the old file and folder after several days. I put the following code in a script file and tried to use crontab to run it every day. The find command worked fine. but the crontab seems not execute the script file.

I also use crontab for other tasks, i.e. rsync, they all work fine. I am wondering what might be the possible reason that crontab won't work in this case. And what could I do alternatively for the job? Thanks!

#!/bin/bash -x

find /media -type d -ctime +18 | xargs rm -rf

my crontab entries are

10 09 * * * /root/rsync-shell.sh &
20 09 * * * /root/chg3gp2avi.sh &
30 09 * * * /root/clean_files_10days.sh &

the first two are the ones I set up before and work fine. The third one is the current one that won't work.

please edit your question to include your crontab entry. Good luck.
Does your crontab work for other scripts?
what does your cron log say?
Have you considered using tmpreaper? It removes old files. It is very configurable. It would get you out of the business of reinventing the wheel.
Just a point, this will delete directories, assuming they were created more than 18 days ago, weren't moved in the last 18 days, and otherwise had no inode status change in the last 18 days, regardless of whether any files within the directories were more recently modified, created, or deleted.

Best Answer

Is crond running?

$ systemctl status crond
* crond.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)

If not try to start it before debugging any further. If you have not configured sudo then use root privileges by some other means, such as logging in as root or via su command.

$ sudo systemctl start crond

comments:

Thanks Sami. I just found that my old script stopped running for a while then I figure cron was somehow disable a while ago. I enable it and now all of them go back to normal status. Thanks!