LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-05-2007, 10:07 PM   #1
justwantin
Member
 
Registered: Aug 2003
Location: Melbourne, Australia
Distribution: Slackware, Slackwarearm
Posts: 878

Rep: Reputation: 120Reputation: 120
scripting help for auto shutdown


I am trying to figure out a way to set up a workstation to shut down automaticaly if the user as not been active on it for a given period of time.

There might be an ap to do this but all I've found are things like powersave which seem to be geared for laptops using acpi/apm amd things geared towards working with a UPS.

I've done something similar to shut down a printer/scanner/fileserver when nobody's up on the lan and there are no jobs scheduled to run, but that was simple using ping to test workstations and grep'ing for at jobs.

This time around I'm not sure what I should be checking for except to see if mplayer or xine is running (they might be watching a dvd or timeshift).

I can sort out the script. I just need some suggestions on what to look for (perhaps with grep)on the workstation to indicate it is being used.

TIA
 
Old 02-05-2007, 11:22 PM   #2
kvnband
Member
 
Registered: Jan 2004
Distribution: Suse 10.2
Posts: 107

Rep: Reputation: 15
Can you check mouse idle time? If so, I would check that first, then check to see if some common apps are running (xine, mplayer, etc..). If idle for > x minutes, then check for xine or mplayer playing media. If not, shut down?
 
Old 02-06-2007, 03:42 AM   #3
justwantin
Member
 
Registered: Aug 2003
Location: Melbourne, Australia
Distribution: Slackware, Slackwarearm
Posts: 878

Original Poster
Rep: Reputation: 120Reputation: 120
I figured on doing something like that but I haven't been able to sort out what/where the info would be on my system and if I could just do it with existing cli tools and a bash script.

I found something called doinkd which looks like it might do the trick. but I was hoping to do this without running a daemon although this ap is in C and probably is no worse when it sleeps than if I used sleep in a bash script

Thanks for the prompt reply

RM
 
Old 02-14-2007, 05:36 PM   #4
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
hello,
cat /proc/interrupts
shows if there is input from mouse and keyboard

Last edited by ygloo; 02-14-2007 at 05:40 PM.
 
Old 02-14-2007, 06:29 PM   #5
justwantin
Member
 
Registered: Aug 2003
Location: Melbourne, Australia
Distribution: Slackware, Slackwarearm
Posts: 878

Original Poster
Rep: Reputation: 120Reputation: 120
Thanks for that. I knew there had to be something I could check just didn't know where to look or what keywords to google.

I'll havve a look next chance I have for some play time:^)
 
Old 02-15-2007, 05:37 AM   #6
justwantin
Member
 
Registered: Aug 2003
Location: Melbourne, Australia
Distribution: Slackware, Slackwarearm
Posts: 878

Original Poster
Rep: Reputation: 120Reputation: 120
Thanks ygloo,

I've got it now.The mouse shares an IRQ with the keyboard (interrupts 2 and 12) Second column is a count indicating activity. To easy!

bash-3.1# cat /proc/interrupts
CPU0
0: 901691 XT-PIC timer
1: 4015 XT-PIC i8042
2: 0 XT-PIC cascade
8: 1 XT-PIC rtc
9: 0 XT-PIC acpi
10: 0 XT-PIC uhci_hcd:usb2
11: 5702 XT-PIC ehci_hcd:usb1, uhci_hcd:usb3, uhci_hcd:usb4, cx88[0], CMI8738-MC6, cx88[0], eth0
12: 119155 XT-PIC i8042
14: 22182 XT-PIC ide0
NMI: 0
ERR: 0
 
Old 02-15-2007, 12:59 PM   #7
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
i think of a screensaver...
it blanks the screen after some idle time

you can modify it to halt the system instead

Last edited by ygloo; 02-15-2007 at 01:06 PM.
 
Old 02-17-2007, 11:01 PM   #8
justwantin
Member
 
Registered: Aug 2003
Location: Melbourne, Australia
Distribution: Slackware, Slackwarearm
Posts: 878

Original Poster
Rep: Reputation: 120Reputation: 120
Thanks once more ygloo.

Just to close this thread with something useful:

I could use a screensaver but that's set to screensaver time. I wanted to be independent of that. The short script below will do the trick with a delay between tests of, say, 40 minutes. I'll also have to test to be sure my daughter is not just watching something with Codeine or Kaffeine, hence no mouse movements. Script would need to be fleshed out a bit. I'd probably run it as a cron job.

#!/bin/bash
# mouseup rm200702018
# A script for testing user activity on mouse
# and shutting down if none. Run as root

TIME=10m #set time between checks, "m" suffix for minutes

# Get a value for mouse interrupt which is 12: on this box.
# Use awk to get the value which is in line 12: column 2.
MOUSE1=`cat /proc/interrupts | grep 12: | awk '{print $2}'`

# Put the value into a log file.
echo "`date` MOUSE1 equals $MOUSE1" > testing.txt

# Wait for [$TIME] before checking again.
sleep $TIME

# Get a another value for mouse interrupt [$TIME] minutes later
MOUSE2=`cat /proc/interrupts | grep 12: | awk '{print $2}'`

# Send value to the log
echo "`date` MOUSE2 equals $MOUSE2" >> testing.txt

# If both values are the same log it then shut down
if [ $MOUSE1 -eq $MOUSE2 ] ; then

echo "`date` shutdown -h now" >> testing.txt
shutdown -h now
fi

#End of script
 
Old 02-17-2007, 11:57 PM   #9
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
Code:
#!/bin/bash
# mouseup rm200702018
# A script for testing user activity on mouse
# and shutting down if none. Run as root

TIME=10m #set time between checks, "m" suffix for minutes
MOUSE_CHECK=`awk '/[Mm]ouse/ {print $2}' /proc/interrupts`

while true
do

    # Get a value for mouse interrupt which is 12: on this box.
    # Use awk to get the value which is in line 12: column 2.
    MOUSE1=$MOUSE_CHECK

    # Put the value into a log file.
    echo "`date` MOUSE1 equals $MOUSE1" > testing.txt

    # Wait for [$TIME] before checking again.
    sleep $TIME

    # Get a another value for mouse interrupt [$TIME] minutes later
    MOUSE2=$MOUSE_CHECK

    # Send value to the log
    echo "`date` MOUSE2 equals $MOUSE2" >> testing.txt

    # If both values are the same log it then shut down
    # useful to quote variables when compare
    if [ "$MOUSE1" -eq "$MOUSE2" ] ; then

        echo "`date` shutdown -h now" >> testing.txt
        shutdown -h now
    fi

done

#End of script
added a while loop to check mouse more than once

Last edited by ygloo; 02-18-2007 at 12:42 AM.
 
Old 02-18-2007, 12:15 AM   #10
justwantin
Member
 
Registered: Aug 2003
Location: Melbourne, Australia
Distribution: Slackware, Slackwarearm
Posts: 878

Original Poster
Rep: Reputation: 120Reputation: 120
Yup that'd work.I had considered using a loop but hadn't thought through if there'd be any disadvantages. I knew it would work without problems as a cron job.
 
Old 02-18-2007, 05:53 AM   #11
justwantin
Member
 
Registered: Aug 2003
Location: Melbourne, Australia
Distribution: Slackware, Slackwarearm
Posts: 878

Original Poster
Rep: Reputation: 120Reputation: 120
This'll do it run from /etc/rc.d/rc.local

Almost thought about putting some of the if statements in as functions but I'm lazy and it's time to call it a day

#!/bin/bash
# /usr/local/mouseup rm200702018
# A script for testing user activity on their mouse
# and shutting down if given programs are not running
# and there has been no mouse activity for declared period
# off time. Run as root

TIME=$1m #set time between checks, "m" suffix for minutes
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 12: | 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
 
Old 02-18-2007, 11:49 AM   #12
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
quoted positional parameter to see it better -
( first thought it is 1m = one minute )

TIME="$1"m #set time between checks, "m" suffix for minutes

you can display shutdown warning -
DISPLAY=:0.0 xmessage -center "Shutting down in 15 sec"

( i wonder if xmessage sends message to all logged users )

Last edited by ygloo; 02-18-2007 at 01:12 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Shutdown rajaniyer123 Linux - Software 1 05-02-2006 11:23 PM
Auto starting and/or scripting Infernal211283 Linux - Newbie 1 03-22-2005 12:41 PM
Auto Shutdown k_ranju Linux - General 3 07-20-2003 04:43 AM
how to auto powerdown at shutdown fysx Linux - Software 1 05-09-2003 03:09 PM
Auto Shutdown at time Crazy Banana Linux - General 3 11-26-2002 07:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration