Skip to content

Instantly share code, notes, and snippets.

@donalod
Created September 22, 2014 14:18
Show Gist options
  • Save donalod/2e8df14f7d74b2c30f23 to your computer and use it in GitHub Desktop.
Save donalod/2e8df14f7d74b2c30f23 to your computer and use it in GitHub Desktop.
APCUPSLogsToGNUPlot
#!/usr/bin/env bash
grep -i "UPS:" ./u > u1
statehigh=""
statelow=""
while read line; do
#echo "$line"
cleanline=$(echo $line|tr -s ' ')
#echo "$cleanline"
date=$(echo $cleanline| cut -f1 -d" ")
#echo $date
reversedate=$(echo $date|awk -F'/' '{print $3"-"$1"-"$2"_"}')
#echo $reversedate
time=$(echo $cleanline| cut -f2 -d" "| sed 's/:/\./g')
#echo $time
minustime=$(echo $time|awk -F'.' '{print $1 "." $2 "." $3-1 }')
#echo $minustime
state=$(echo $cleanline| cut -f3- -d" " | sed 's/UPS\: Compensating for a high input voltage\./5/;s/UPS\: No longer compensating for a high input voltage\./1/;s/UPS\: .*Battery.*/10/')
if [[ $state = "5" ]]; then
echo "${reversedate}${time} ${state}"
echo "${reversedate}${minustime} 1"
elif [[ $state = "1" ]]; then
echo "${reversedate}${time} ${state}"
echo "${reversedate}${minustime} 5"
else
echo "${reversedate}${time} ${state}"
fi
done < u1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment