#!/bin/bash INPUT="hf2.jpg" # or something like that, according to your grabber WORKPNG1="workpng1.png" WORKPNG2="workpng2.png" GRABBER="qrsspig" LIMIT="50" # the lowes allowed intensity for continuing the grabber while true ; do # never stop rm $WORKPNG1 rm $WORKPNG2 # we need to analyze only the spectral part of the picture: convert -crop 500x400+100+150 $INPUT $WORKPNG1 # the dimensions and position of the "data" part # now you can check if the selection was OK in workpng1.png convert -resize 50x40\! $WORKPNG1 $WORKPNG2 # decrease the size and some noise # min blue intensity: MIN=$( convert $WORKPNG2 txt: | awk -F "(" '{ print $2 }' | awk -F ")" '{print $1 }' | \ awk -F "," '{ print $3 }' | sort -n | head -3 | tail -1 ) # max blue intensity: MAX=$( convert $WORKPNG2 txt: | awk -F "(" '{ print $2 }' | awk -F ")" '{print $1 }' | \ awk -F "," '{ print $3 }' | sort -n | tail -1 ) echo -n "max:$MAX min:$MIN" # blue shoud work for most of the grabbers. But you can select RED by awk -F "," '{ print $1 }' or GREEN by awk -F "," '{ print $2 }' if [ "$MAX" -lt "$LIMIT" ] ; then echo " Killing the grabber!" for PID in $( ps -ef | grep -v grep | grep "$GRABBER" | awk '{ print $2 }' ) ; do sudo kill $PID ; done else echo " OK" fi sleep 20s # ?? done