3

I have a directory that gets filled with images from a web service and the images only need to exist on my server for 5 minutes after they've been placed. I tried using tmpreaper but I couldn't get it to work. I did the following command:

sudo crontab -e

* * * * * tmpreaper 5m /my_image/dir

I checked that the cron was running by pgrep cron and I got a PID. However, the images are still in the directory. Running the command manually works perfectly fine, however it's not working through cron.

2 Answers 2

2

In my experience, cron doesn't like raw commands in their files. Make a simple bash script that looks like:

#!/bin/bash
tmpreaper 5m /my_image/dir

Save the script somewhere solid, make it executable, and change your cron to bash /path/to/script.

I've had issues with permissions with cron as well. Make sure it is being run by the correct user you are expecting it to.

0
* * * * *  find /yourDir/ -type f -mmin +5  -exec rm -f {} +

Command will run after every min and delete your files present in a directory that is older than 5 min. resource : https://crontab.guru/every-1-minute

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .