#!/bin/bash ####################################################################### # /usr/local/mouseup RM200702018 # A script that tests for user activity based on mouse activity # shuts down if given programs are not running and there has been no # mouse activity for declared period of time. Mouse activity is based # on a comparison of output of the mouse device as listed in the table # /proc/interrupts. # You would have to check /proc/interrupts and determine which line # number belongs to your mouse. On the box this script runs on, there # are two interupt entries "i8402". Probably every mobo I've had shares # IRQ's so this is not unusual. I determined that the one on line 12 # belonged to the mouse (the other is the keyboard) and edited so that # variable INTRPT_LINE=12. # This script creates a log file /var/log/mouseup which is overwritten # by the first new log entry made by mouseup $INTRPT_LINE after a boot. # I run this script at boot by putting the following line in # /etc/rc.d/rc.local: "/usr/local/bin/mouseup 45 > /dev/null 2>&1 $". The # the number following the command sets the period of time between checks. ####################################################################### TIME="$1"m #set time between checks, "m" suffix for minutes INTRPT_LINE=12 LOGFILE=/var/log/mouseup.log #this is where all activity will be logged test -n "$TIME" if [ $? -eq 1 ]; then echo -e "\nYou have to declare how many minutes delay" echo -e "between 1st and 2nd check for mouse activity.\n" echo -e "Usage: mouseup [minutes]\n" exit fi echo "`date` Starting mousup. Delay time set to $TIME." > $LOGFILE # By using single ">" a new log is created. All others are ">>" adding new lines to existing logfile. while true do MOUSE1=`cat /proc/interrupts | grep $INTRPT_LINE: | awk '{print $2}'` echo "`date` MOUSE1 equals $MOUSE1" >> $LOGFILE sleep $TIME ps -A | grep "codeine" > /dev/null 2>&1 if [ $? -eq 0 ] ; then CODEINE_CHK=0 echo "`date` Codeine is running" >> $LOGFILE else CODEINE_CHK=1 echo "`date` Codeine is not running." >> $LOGFILE fi ps -A | grep "kaffeine" > /dev/null 2>&1 if [ $? -eq 0 ] ; then KAFFEINE_CHK=0 echo "`date` Kaffeine is running" >> $LOGFILE else KAFFEINE_CHK=1 echo "`date` Kaffeine is not running." >> $LOGFILE fi MOUSE2=`cat /proc/interrupts | grep 12: | awk '{print $2}'` echo "`date` MOUSE2 equals $MOUSE2" >> $LOGFILE if [ $MOUSE1 -eq $MOUSE2 -a $CODEINE_CHK -eq 1 -a $KAFFEINE_CHK -eq 1 ] ; then echo "`date` shutdown -h now" >> $LOGFILE shutdown -h now exit fi done #End of script