0

I have this line in my crontab to delete old files:

1 * * * * find /var/log/abc/ -mtime +7 -type f -delete

Unfortunately, it does not work.

I have attempted to give all users permission to clear that folder using

chmod +777 /var/log/abc

But the chmod did not work. What else could I try?


Following the suggestions to log the output, I am finding that this is in the logs:

/bin/sh: 1: find: not found

So I think I need to set my path correctly...

Ginger
  • 103
  • 6
  • You could add `> /var/tmp/out 2>&1` and then look at that file for what errors are being generated – Mark Wagner Feb 11 '20 at 23:27
  • Try running the command manually and see if it throws some errors.`find /var/log/abc/ -mtime +7 -type f -delete` – kn330 Feb 12 '20 at 09:26

1 Answers1

2

As a good practice add the user who is going to execute this crontab.

1 *    * * *   root    find /var/log/abc/ -mtime +7 -type f -delete

Did you proved that the find is working properly outside of cron?

Try to execute it manually and see what happens, there's nothing wrong with cron.

As a second good practice try to log what cron does to syslog for example using logger:

1 *    * * *   root    find /var/log/abc/ -mtime +7 -type f -delete 2>&1 | logger -t cron_find_delete

The

2>&1

at the end is going to throw sterr and stdout to the logger.

VictorMJ
  • 108
  • 1
  • 5