-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjanitor
More file actions
executable file
·63 lines (52 loc) · 1.41 KB
/
Copy pathjanitor
File metadata and controls
executable file
·63 lines (52 loc) · 1.41 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
ideal_free=10 # % of filesystem
video_size=600 # in seconds
nr_cameras=10 # number of cameras
shortest_rm_pause=1
# delete rate at least 4x of the video recording rate
longest_rm_pause=$(($video_size / $nr_cameras / 4))
remove_old_videos() {
target_free="$1"
rm_pause=$shortest_rm_pause
while true; do
total=$(($(stat -f --format="%b" .)))
free=$(($(stat -f --format="%a" .)))
freepct=$(( $free * 100 / $total ))
echo "Free ${freepct} target ${target_free}"
if [ "$freepct" -ge "$target_free" ]; then
break
fi
oldest=$(ls -c *.mkv | tail -1)
if [ "$oldest" = "" ]; then
echo "Disk full for other reason than videos!"
# mail administrator
break
fi
echo "Removing $oldest"
prermfree=$free
rm -f $oldest
sleep $rm_pause
sync
free=$(($(stat -f --format="%a" .)))
if ! [ "$free" -gt "$prermfree" ]; then
echo "Free block count $free did not increase over $prermfree"
rm_pause=$(($rm_pause * 2))
if [ "$rm_pause" -gt "$longest_rm_pause" ]; then
rm_pause=$longest_rm_pause
fi
echo "Increasing pause between removals to $rm_pause"
fi
done
}
while true; do
total=$(($(stat -f --format="%b" .)))
free=$(($(stat -f --format="%a" .)))
freepct=$(( $free * 100 / $total ))
date
echo ${freepct}% free
if [ "$freepct" -lt "$ideal_free" ]; then
echo "Free space less than ${ideal_free}%"
remove_old_videos $(($ideal_free + 1))
fi
sleep 3600
done