I use a pendrive on my openwrt device. On this pendrive a ip cam save video (only on detects movement).
The problem is: when the pen drive is full ip cam stop to save video.
Is there a way to auto delete the old files? Per example when the disk space exceeds 95% of sizeopenwrt delete OLD files until 85% of size(from 95% to 85%). In this way the ip cam have always size to save data and I lost only old video.
I use -type d (directory) because my ip cam creates a folder for each new day.
So basically this cron job deletes all directories older than 90 days with their contents.
timeout -k 20m 15m will try to end the task after 15 minutes (SIGTERM).
If it fails, timeout tries to kill the task after 20min. (SIGKILL)
timeout needs to be separately installed. opkg install coreutils-timeout
To delete old files only after a certain usage threshold is reached on the filesystem, you could create a script that checks the file system usage.
For example, you could use this to get the usage threshold: df -k /mnt/sda1 | tail -1 | awk '{print $5}'
Output: 9%
To only get the number (for easier comparison in scripts) df -k /mnt/sda1 | tail -1 | awk '{print $5} | grep -Eo '[0-9]+'
Output: 9
I cannot use "time" as delete criteria. The ip cam save video only on motion detection and not continuously. It save short video (and files) every time there is a motion detection. If I use "file time" are delete criteriathe device can delete all files (because the ip cam hasn't registered recently) also if there is free space on storage. I should check storage status and delete old files. Is this possible witha cron script?
I'm not an expert, I have configuared my device some months ago to works with openwrt (samba, external storage, wifi connection, ...) and now it works. Is there a GUI package for cron? If possible I'like avoid the shell command. I have use it on device configuration but I have spent many time to do it
USB is temporary. I will replace it with a small hard disk after all works. Is a mechanical hard disk or an SSD better fot this use?
I think the correct criteria must be the storage use quote. The cron script must check the % of storage use and then delete the files from the older. For example every 15 minutes the script must control if storage quote is more that 85% and if this is TRUE delete the files (from the more older) until have a storage quote of 65%. In this way there is always free space for new videos and only old videos will be delete. This is possible with a cron script?
Because if the cam rarely records you would risk deleting all the videos for no reason (just because they are old not because need more space for new videos)
Since you are not writing continuously or at high rates, either SSD or spinning-platter is fine. Except for enterprise-grade (expensive) hard drives, SSDs are probably a better choice between lower power draw, no vibration/drop problems, and even just availability.