I have a webcam that is uploading a image every few minutes via FTP into a directory. The webcam unfortunately has a bug which uploads two images at once. (the vendor does not want to fix it…). The image is still different so I can not check the md5sum of the .jpg and delete the duplicated one.
The filename of the image is similar, but still different. It looks like this:
- Jan 3 09:43 image220103_094305_20.jpg
- Jan 3 09:43 image220103_094306_00.jpg
The format is as follows:
imageYYMMDD_HHMMSS_??.jpg
My goal is to keep the first uploaded image and delete the second one.
My idea was to use “stat” and check the modified time. However, stat goes very much into detail and even shows the seconds when it was uploaded. So my question is:
Is it possible to limit the time when it was modified to minutes? I don’t care about the seconds or further.
If two images get uploaded at 09:43, I want to delete the last one.
The bash script will be executed via a crontab every hour.
My approach would be:
- List all files in the directory and their modified time, limited until minutes (don’t show seconds)
- If there are any files with the same modified time, delete the last one of the result