Last active
May 13, 2018 02:20
Remove old recordings of camera.
This file contains hidden or 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
size=`/usr/bin/du -h -s -BG /mnt/disk0/cam0 2>/dev/null | cut -d "G" -f 1 2>/dev/null` | |
if [ 0 -ne $? ] | |
then | |
text="ERROR Can't get size of the cam 0" | |
echo "$text" | mailx -A gmail -s "$text" foo@bar.com >/dev/null 2>&1 | |
exit 1 | |
fi | |
if [ 200 -gt $size ] | |
then | |
# nothing to do | |
exit 0 | |
fi | |
# DO NOT USE "sort | head". It produces Broken pipe error. | |
# http://archive.is/Vq4kA | |
# http://archive.is/8fJxg | |
# | |
# Bourne shell does not support 'process substitution'. | |
# So I use a temporary file to store sort result. | |
tmp_file=`mktemp` | |
/usr/bin/find /mnt/disk0/cam0/rec -mindepth 2 -type d 2>/dev/null | sort >> "$tmp_file" | |
dir=`head -1 "$tmp_file"` | |
rm "$tmp_file" | |
if [ "" != "$dir" ] | |
then | |
rm -r "$dir" | |
fi | |
tmp_file=`mktemp` | |
/usr/bin/find /mnt/disk0/cam0/rec -mindepth 1 -maxdepth 1 -type d 2>/dev/null | sort >> "$tmp_file" | |
dir=`head -1 "$tmp_file"` | |
rm "$tmp_file" | |
if [ "" != "$dir" ] | |
then | |
n=`ls "$dir" | wc -l` | |
if [ 0 -eq $n ] | |
then | |
rm -r "$dir" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment