#!/bin/sh
#
# $Id: monEvents.sh,v 1.1 2009/01/11 08:01:57 guru Exp $
#
# monitor the proc 'events/0' and if this runs away, i.e.
# consuming in 10 minutes more than 2 CPU seconds,
# we offer the user a reboot of the FR
#
# co guru@unixarea.de

DISPLAY=:0.0 export DISPLAY

printf "CPU time diff: "
cpuOld=0
while true; do
    cpuNow=`ps --no-heading -C events/0 -o time | awk -F : '{print $1*3600+$2*60+$3}'`
    if [ ${cpuOld} -eq 0 ]; then
       diff=0
    else
       diff=`expr ${cpuNow} - ${cpuOld}`
    fi
    printf "%d " ${diff}
    if [ ${diff} -gt 2 ]; then
        printf "! "
        /home/root/sys/shuttdown.py
    fi
    cpuOld=${cpuNow}
    sleep 600
done
