简体   繁体   中英

crontab is not deleting the files in linux

I am trying to delete all the pdf files which are more than 30 days old at 11:30 PM

I added the below given code in crontab

30 23 * * * find /var/www/html/site/reports/ -name "*.pdf" -type f -mtime +30 | xargs -I {} rm -f {} \;

But it doesn't delete the files.

Can you please check what the issue is?

The crontab details

-rw-r--r--. 1 root root 532 Sep 30 11:14 crontab

One of the files which i need to delete

-rw-r--r-- 1 apache apache 15215 Jul 25 11:24 sales_report.pdf

You missed user and PATH. This may help

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

30 23 * * * root find /var/www/html/site/reports/ \( -name "*.pdf" \) -type f -mtime +30 -exec rm {} \; >> /tmp/debug_cron 2>&1

And then check /tmp/debug_cron

我有这个工作的Linux盒子。

30 23 * * * find /var/www/html/site/reports/ \( -name "*.pdf" \) -type f -mtime +30 -exec rm {} \;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM