#!/bin/bash
export DISPLAY=:0
export EMAIL=$HOSTNAME'@lucidnetworks.net'
time=$(date +"%m-%d-%Y_%T")
rand=$(od -N 4 -t uL -An /dev/urandom | tr -d " ") && echo $rand
dir=/tmp/$rand
echo $dir
mkdir $dir
scrot $dir/$time.png
convert $dir/$time.png -colorspace Gray $dir/$time.tif
text=$(tesseract $dir/$time.png stdout)
if [[ $text == *"Aw, Snap"* || $text == *"Aw,Snap"* ]]
then
  echo $text | mutt -s "$HOSTNAME Google Aw, Snap! Crash. Taking Action!" -a $dir/$time.png -- sloeckle@lucidnetworks.net
  rm $dir/$time.png $dir/$time.tif
  killall chrome
  /usr/bin/google-chrome --start-fullscreen google.com &
  sleep 10
  time=$(date +"%m-%d-%Y_%T")
  scrot $dir/$time.png
  convert $dir/$time.png -colorspace Gray $dir/$time.tif
  text=$(tesseract $dir/$time.png stdout)
  echo $text | mutt -s "$HOSTNAME Google Aw, Snap! Crash. Action Completed!" -a $dir/$time.png -- sloeckle@lucidnetworks.net
else
#  time=$(date +"%m-%d-%Y_%T")
#  scrot $dir/$time.png
#  echo $text | mutt -s "$HOSTNAME No Google Aw, Snap! Message! Going About Our Business." -a $dir/$time.png -- sloeckle@lucidnetworks.net
#  rm $dir/$time.png
fi
#rm -rf $dir
