-1

Below is my crontab entry :

* 4 * * * find /path/to/apache/logs -name "apache_*" -type f -mtime +20 -exec rm -f {} \; > /home/user/Deleted-`date +\%Y\%m\%d\%H\%M\%S`.log 2>&1

it is finding the files older than 20 days and removes those without any issue but I'm not able to capture those deleted files' name on the log file.

I have even used the above command in a bash script and tried as below but the same issue.

* 4 * * * /path/to/log_rotate.sh > /home/user/Deleted-`date +\%Y\%m\%d\%H\%M\%S`.log 2>&1

I'm not sure where I'm going wrong. Any suggestion please.Thanks

voltas
  • 553
  • 7
  • 24
  • What's the problem? Empty log file? Why do you expect `rm -f` to output anything at all? – Jens Apr 21 '17 at 14:38
  • Possible duplicate of [How to log cron jobs?](https://stackoverflow.com/q/4811738/608639) – jww Oct 25 '18 at 20:20

1 Answers1

1

Add the -v option to the rm command so that it prints which files it's deleted.

* 4 * * * find /path/to/apache/logs -name "apache_*" -type f -mtime +20 -exec rm -fv {} \; > /home/user/Deleted-`date +\%Y\%m\%d\%H\%M\%S`.log 2>&1