Skip to content

Instantly share code, notes, and snippets.

@scottshuffler
Created February 27, 2017 21:45
Show Gist options
  • Save scottshuffler/0004f42bab65ba69a3267172640706f8 to your computer and use it in GitHub Desktop.
Save scottshuffler/0004f42bab65ba69a3267172640706f8 to your computer and use it in GitHub Desktop.
#!/bin/bash
NC='\033[0m'
BLACK='\033[0;30m' # Black
RED='\033[0;31m' # Red
GREEN='\033[0;32m' # Green
YELLOW='\033[0;33m' # Yellow
BLUE='\033[0;34m' # Blue
PURPLE='\033[0;35m' # Purple
CYAN='\033[0;36m' # Cyan
WHITE='\033[0;37m' # White
beedir=/usr/local/bee/beemon
hosts=( rpi2b rpi4b rpi5b rpi6b rpi7b )
today=$(date "+%Y-%m-%d")
function check_dir() {
local pi=$1
if [[ ! -d "$beedir/$pi/$today" ]]; then
# echo "$pi: No directory exists for today ($today)"
printf "${RED} %s: No directory exists for today (%s)${NC}\n" $pi $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 ($today)"
printf "${RED} %s: No directory exists for video today(%s)${NC}\n" $pi $today
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"
printf "${GREEN} %s: Last video upload: %d seconds ago${NC}\n" $pi $how_long_ago_vid
fi
if [[ (! -d "$audiodir") || $(ls -1 "$audiodir" | wc -l) == 0 ]]; then
# echo "$pi: No directory exists for audio for today ($today)"
printf "${RED} %s: No directory exists for audio today(%s)${NC}\n" $pi $today
#printf ""
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"
printf "${GREEN} %s: Last audio upload: %d seconds ago${NC}\n" $pi $how_long_ago_aud
fi
}
if [[ ! -d $beedir ]]; then
echo "error: $beedir doesn't exist"
exit 1
fi
echo ""
while [ 1 -le 5 ];
do
clear
for h in ${hosts[@]}; do
check_dir $h
echo ""
done
sleep 1m
today=$(date "+%Y-%m-%d")
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment