Skip to content

Instantly share code, notes, and snippets.

@alekratz
Created June 15, 2016 19:02
Show Gist options
  • Save alekratz/39e7a31eafe715faf018fb7e4bac5e4b to your computer and use it in GitHub Desktop.
Save alekratz/39e7a31eafe715faf018fb7e4bac5e4b to your computer and use it in GitHub Desktop.
#!/bin/bash
beedir=/usr/local/bee/beemon
hosts=( rpi21 rpi22 rpi23 rpi24 )
today=$(date "+%Y-%m-%d")
function check_dir() {
local pi=$1
# Check if today directory exists
if [[ ! -d "$beedir/$pi/$today" ]]; then
echo "$pi: No directory exists for today ($today)"
return
fi
local todaydir="$beedir/$pi/$today"
local audiodir="$todaydir/audio"
local videodir="$todaydir/video"
local now=$(date +%s)
if [[ (! -d "$videodir") || $(ls -1 "$videodir" | wc -l) == 0 ]]; then
echo "$pi: No directory exists for video for today ($videodir)"
else
video_last_upload=$(date --date="$(ls -tl --time-style="+%Y-%m-%d %H:%M:%S" "$videodir" | tail -n +2 | head -n 1 | awk '{ print $6 " " $7; }')" +%s)
how_long_ago_vid=$((now - video_last_upload))
echo "$pi: Last video upload: $how_long_ago_vid seconds ago"
fi
if [[ (! -d "$audiodir") || $(ls -1 "$audiodir" | wc -l) == 0 ]]; then
echo "$pi: No directory exists for audio for today ($audiodir)"
else
audio_last_upload=$(date --date="$(ls -tl --time-style="+%Y-%m-%d %H:%M:%S" "$audiodir" | tail -n +2 | head -n 1 | awk '{ print $6 " " $7; }')" +%s)
how_long_ago_aud=$((now - audio_last_upload))
echo "$pi: Last audio upload: $how_long_ago_aud seconds ago"
fi
}
if [[ ! -d $beedir ]]; then
echo "error: $beedir doesn't exist"
exit 1
fi
for h in ${hosts[@]}; do
check_dir $h
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment