Crontab to delete files

Viewed 98

I´m very new to Linux, and right now I am trying to delete some video recordings of my security camera (from the FTP server) at every 30 minutes.

I already used: pi@raspberrypi:~$ find path/toMy/Video/recordings/ -type f -mmin +30 -delete

After that, I used crontab -e choose the Nano option and typed:

*/30 * * * * find path/toMy/Video/recordings/ -type f -mmin +30 -delete

Saved it, but it doesn´t seem to work. What am I doing wrong?

3 Answers

Make sure you use the full path to find, for example:

% which find
/usr/local/opt/findutils/libexec/gnubin/find

Also, use absolute path (not relative path) for your directory.

Then:

*/30 * * * * /usr/local/opt/findutils/libexec/gnubin/find /path/toMy/Video/recordings/ -type f -mmin +30 -delete

To debug:

  1. You can also redirect the output of your crontab entry.
*/30 * * * * find path/toMy/Video/recordings/ -type f -mmin +30 -delete &> /<your-path>/cron.out
  1. Check for the cron logs in /var/log/

You should consider saving output of cron in a file to debug or simply try to run the command in terminal to see output. To save output of cron in file you can try:

*/30 * * * * command >/home/user/cron.log 2>&1
Related