summaryrefslogtreecommitdiffstats
path: root/satellit_installer/static_files/dnbd3/etc/cron.daily/dnbd3-stage4-cleanup
blob: 7a43f0aebb2b5add4d7e8f56733a0b9e503af7ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash

# Find all .meta files in stage 4 directory
mapfile -d '' list < <( find /srv/openslx/nfs/stage4/bwlp/ -type f -name "*.meta" -print0 )

now="$( date +%s )"
for file in "${list[@]}"; do
	# get the atime value from it; this is the last time a client asked for the according image
	atime="$( grep -oP '(?<=^atime=).*$' "$file" )"
	diff="$(( (now - atime) / 86400 ))"
	# check if atime is more than 60 days ago, or continue with next image
	(( diff > 60 )) || continue
	# Older than 60 days, fire away
	file="${file%.meta}"
	rm -f -- "$file" "$file".* # No space between $file and .* !!
done
exit 0