-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspacer.sh
executable file
·36 lines (28 loc) · 1011 Bytes
/
spacer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh
# scan directory and interactivly delete oldest file while below threshold
threshold=1000000000
datadir=/tmp
##############################################################################
checkfree() {
sync
freespace=$( df $datadir | tail -n 1 )
freespace=$( echo $freespace | awk -F " " '{print $4}' )
echo "$freespace"
}
getoldestfile() {
oldestfile="$(find $datadir/ -type f -printf '%p\n' | sort | head -n 1)"
#oldestfile="$(ls -1t $datadir | tail -1)"
echo "$oldestFile"
}
while [ `checkfree` -le "$threshold" ]; do
echo "######################################################"
echo "Media ($datadir) below threshold (Free: $(checkfree) / threshold: $threshold)"
oldestfile=`getoldestfile`
echo "Oldest File: $datadir$oldestfile"
# rm -i "$datadir/$oldestfile"
# touch "$datadir/$oldestfile" 2&1>/dev/null
#mv $datadir/$oldestfile /mnt/hdd/tmp
sleep 1
done
echo "Media ($datadir) Free: `checkfree` / threshold: $threshold"
exit 0