I was having trouble with my hard drive filling up while pulling images from GOES-16 and GOES-17 satellites. 32gb filles up really quick on my odroid!
So I wrote a ghetto little script that removes files older than 2 days, every day, except for the full color/ full disk images which are the ones I want to keep. I also leave the national weather service images since they take up very little space.
Here it is;
First, create your script
# nano /home/radio/goes/goes_remove_old.sh
Copy this in it, modifying the paths if needed.
find /var/www/wx/goes/goes16/m1/ch02/* -mtime +2 -exec rm {} \;
find /var/www/wx/goes/goes16/m1/ch07/* -mtime +2 -exec rm {} \;
find /var/www/wx/goes/goes16/m1/ch07_enhanced/* -mtime +2 -exec rm {} \;
find /var/www/wx/goes/goes16/m1/ch13/* -mtime +2 -exec rm {} \;
find /var/www/wx/goes/goes16/m1/ch13_enhanced/* -mtime +2 -exec rm {} \;
find /var/www/wx/goes/goes16/m2/ch02/* -mtime +2 -exec rm {} \;
find /var/www/wx/goes/goes16/m2/ch07/* -mtime +2 -exec rm {} \;
find /var/www/wx/goes/goes16/m2/ch07_enhanced/* -mtime +2 -exec rm {} \;
find /var/www/wx/goes/goes16/m2/ch13/* -mtime +2 -exec rm {} \;
find /var/www/wx/goes/goes16/m2/ch13_enhanced/* -mtime +2 -exec rm {} \;
find /var/www/wx/goes/goes17/fd/ch13/* -mtime +2 -exec rm {} \;
find /var/www/wx/goes/ -type d -empty -delete
Then, depending on permissions either edit the user, or, root crontab file. For my setup, it’s root. Again. Ghetto on a private lan. Whatever.
# sudo /bin/zsh
$ crontab -e
Put this line in there, modifying paths if needed.
# everyday at 1am, delete the GOES files older than 48 hours (2 days)
0 1 * * * /home/radio/goes/goes_remove_old.sh >/dev/null 2>/dev/null
Exit and save the file.
That’s it, now at 1am every day, all files older than 48 hours will be deleted, saving space for more of those sweet sweet full color images from space! Hope this helps someone else 🙂