Created
March 11, 2017 09:53
-
-
Save harrygg/5c2a067df1b6934b09a5e1b27580c6ab to your computer and use it in GitHub Desktop.
Runs every day and checks if disk space is less than 5 GB, then deletes some files until free space is bigger than 5 GB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# set -x | |
# Shell script to monitor or watch the disk space | |
cd /home/camera/FI9831P_00626E654229/record | |
free=`df -k --output=avail "$PWD" | tail -n1` | |
treshold=5000000 #5GB Free space needed | |
if [ $free -lt $treshold ]; then | |
echo "less than 10GBs free! Cleaning some files" | |
while [ $free -lt $treshold ] | |
do | |
oldest_file="$(ls -lt | grep -v '^d' | tail -1 | awk '{print $NF}')" | |
file_size=`stat --printf="%s" $oldest_file` | |
echo Removing $oldest_file with size $file_size bytes. | |
rm $oldest_file | |
# sleep 1 | |
free=`df -k --output=avail "$PWD" | tail -n1` | |
echo Used space after removal $free | |
done | |
else | |
echo $free are in available | |
fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment