| Author |
Message |
steel_j

Joined: 07 Nov 2008 Posts: 4 Location: Montreal, Canada
|
Posted: Thu 27 Nov 2008, 17:49 Post subject:
Howto: auto-shutdown after period of inactivity Subject description: System poweroff after set idle time |
|
Hi, new Puppy user, old Linux user
I'm am running Puppy 4 on my HP Pavilion ZE-5700 series laptop.
I quickly noticed there was no real support for auto-suspend to RAM or disk or any type of hibernate. None that worked for me anyway.
Big distros support this very well on my portable,but they are sluggish and I moved to Puppy for speed and usability.
I did some research and there is very little info available. I noticed also that I did not need to suspend because Puppy is by design so quick to boot that it is faster from a cold boot than any disro I know resuming from sleep states.
But....I still needed Puppy to poweroff by itself when I went away.
I found a script and modified it for Puppy. It uses Puppy's own native shutdown script to properly halt the sysem.
You can modify it with your own time and add up to 2 applications that will prevent shutdown if they are found to be running. My own setup is 30 minutes of inactivity (based on mouse / touchpad use) and If mplayer or gxine are running the shutdown will not occur (In case I am watching a movie).
Save this to your "startup" folder as mouseup.sh and give it permision (chmod +rx). It will startup at boot by itself. I tested it and it works flawless.
| Code: | #!/bin/bash
# /root/startup/mouseup (2008-11-24)
# A script for testing user activity on their mouse
# and shutting down if given programs (2) are not running
# and there has been no mouse activity for declared period
# off time. Run as root
TIME=30m #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 "mplayer" > /dev/null 2>&1 #Replace with your own software
if [ $? -eq 0 ] ; then
PROGA_CHK=0
echo "`date` Mplayer is running" >> $LOGFILE
else
PROGA_CHK=1
echo "`date` Mplayer is not running." >> $LOGFILE
fi
ps -A | grep "gxine" > /dev/null 2>&1
if [ $? -eq 0 ] ; then
PROGB_CHK=0
echo "`date` Gxine is running" >> $LOGFILE
else
PROGB_CHK=1
echo "`date` Gxine 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 $PROGA_CHK -eq 1 -a $PROGB_CHK -eq 1 ] ; then
echo "`date` shutdown -h now" >> $LOGFILE
echo "shutting down"
#/usr/X11R7/bin/restartwm ---for testing purposes---
/usr/X11R7/bin/wmpoweroff
exit
fi
done
#End of script
|
This original version of this script can be found here:
http://www.linuxquestions.org/questions/linux-general-1/scripting-help-for-auto-shutdown-525935/
|
|
Back to top
|
|
 |
jrb

Joined: 11 Dec 2007 Posts: 972 Location: Smithers, BC, Canada
|
Posted: Fri 28 Nov 2008, 22:59 Post subject:
|
|
Thanks steel_j
Followed your instructions, changed programs, changed time. Worked perfect!
|
|
Back to top
|
|
 |
steel_j

Joined: 07 Nov 2008 Posts: 4 Location: Montreal, Canada
|
Posted: Fri 28 Nov 2008, 23:30 Post subject:
Glad to help... |
|
Glad to help
Also, if you don't want it to shutdown when you are dowloading a large file you can put your browser as one of the two program that prevent shutdowns (i.e Firefox or Seamonkey)
|
|
Back to top
|
|
 |
vtpup

Joined: 15 Oct 2008 Posts: 1077 Location: Republic of Vermont
|
Posted: Sat 29 Nov 2008, 01:32 Post subject:
|
|
Thanks, this will come in very handy.
|
|
Back to top
|
|
 |
hitchup
Joined: 27 Sep 2008 Posts: 36 Location: Arkansas USA
|
Posted: Sun 18 Jan 2009, 20:29 Post subject:
|
|
Great script. Simply works. This should included in puppy.
_________________ Toshiba A205:S4777; Vista HP(Fading); Puppy Live CD(Rising)
|
|
Back to top
|
|
 |
Pizzasgood

Joined: 04 May 2005 Posts: 6270 Location: Knoxville, TN, USA
|
Posted: Mon 19 Jan 2009, 03:19 Post subject:
|
|
Cool, except for two points.
A: you should also check the keyboard, not just the mouse.
B: that script assumes the mouse interrupt is 12. Mine is not. Maybe this is because I use a usb mouse? I don't know whether those interrupt numbers are standardized. Anyways, my mouse (actually, the usb hub it's plugged into) is at interrupt 23. Also, the thread you linked to states that keyboards are on interrupt 2, but mine is at 1.
| Code: | # cat /proc/interrupts
CPU0
0: 66 IO-APIC-edge timer
1: 49768 IO-APIC-edge i8042
3: 2 IO-APIC-edge
4: 2 IO-APIC-edge
6: 3 IO-APIC-edge floppy
7: 0 IO-APIC-edge parport0
8: 1 IO-APIC-edge rtc
9: 1 IO-APIC-fasteoi acpi
14: 42920 IO-APIC-edge ata_piix
15: 0 IO-APIC-edge ata_piix
16: 1540246 IO-APIC-fasteoi uhci_hcd:usb4, HDA Intel
18: 9042926 IO-APIC-fasteoi uhci_hcd:usb3, bttv0
19: 36804 IO-APIC-fasteoi ata_piix, uhci_hcd:usb2
22: 951334 IO-APIC-fasteoi eth0
23: 430266 IO-APIC-fasteoi uhci_hcd:usb1, ehci_hcd:usb5
NMI: 0 Non-maskable interrupts
LOC: 12166285 Local timer interrupts
TRM: 0 Thermal event interrupts
SPU: 0 Spurious interrupts
ERR: 0
MIS: 0
# |
I think a key item here is the 'i8042' that is displayed on my interrupt 1. My understanding is that the 'i8042' corresponds to the PS/2 keyboard and mouse ports. So you could use grep to grab that line without having to hardcode an interrupt. But that doesn't take care of a USB keyboard or mouse. Interrupt 23 corresponds to my USB hub, not the mouse. Anything else plugged into the hub will also show activity. In some ways that's good - if I play with my gamepad or wacom tablet it will show activity. So you could grep to find all the USB entries too. But there might be times when that's wrong, such as if you have a USB drive, in which case the system's normal operation might show activity there. On my system, interrupts 16 and 18 are changing even when the machine is idle. I believe one of them corresponds to my printer. I don't remember what the other is, and I don't feel like crawling under my bed to find out. I'd rather crawl into bed, and will do that shortly.
I suppose you could have it try to detect whether the user was using a usb or a ps/2 mouse first before choosing what to monitor. Or you could just explain how to determine the corresponding interrupt and let the program accept another parameter so the user can specify without having to edit the script. (They can check by setting up a while loop that cat's the file and then sleeps for a second, then play around with wiggling the mouse and see which numbers only change when the mouse is active. Same for keyboard and other devices.)
Anyways, I'm starting to have trouble typing. G'night.
_________________ Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib

|
|
Back to top
|
|
 |
praveenmallar
Joined: 10 Dec 2008 Posts: 7
|
Posted: Wed 04 Feb 2009, 04:38 Post subject:
|
|
I'm using Asus eeepc with puppy 4.1
is there a way to shutdown puppy on lid-closure of the laptop?
|
|
Back to top
|
|
 |
Pizzasgood

Joined: 04 May 2005 Posts: 6270 Location: Knoxville, TN, USA
|
Posted: Sat 07 Feb 2009, 01:13 Post subject:
|
|
I haven't looked into it yet, but I think in some laptops the lid-close signal registers as a keyboard stroke. You might try using xev to see if that's the case with yours, and which keycode it uses. Then you could map that keycode to do whatever you want.
_________________ Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib

|
|
Back to top
|
|
 |
ferikenagy
Joined: 20 Nov 2006 Posts: 53
|
Posted: Fri 20 Feb 2009, 12:34 Post subject:
cups inactivity too |
|
we are using puppy as an CUPS LAN printing server too.this computer can be power on remotely from LAN using Wake On Lan (WOL) command from a remote (windows/Linux computer). My problem was how to stop it, after not using it.First off all I tried with using tightVNC server on it, permitting to login from remote and to power down the computer, but it was not confortable, and it happens often that simply we forgot to power off remotely or locally the computer after printing. So I was very glad of this posted script, and I completed with keyboard and cups monitoring activity.The cups activity is monitored by comparing the size of "/var/cups/log/page_log" file.
the modified script is (mouseup):
##############
| Code: | #!/bin/bash
# /root/startup/mouseup (2008-11-24)
# A script for testing user activity on their mouse
# and shutting down if given programs (2) are not running
# and there has been no mouse activity for declared period
# off time. Run as root
TIME=15m #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
KEYB1=`cat /proc/interrupts | grep ' 1:' | awk '{print $2}'`
echo "`date` KEYB1 equals $KEYB1" >> $LOGFILE
CUPS1=`ls -g /var/cups/log/page_log | cut -d ' ' -f 4`
echo "`date` CUPS1 equals $CUPS1" >> $LOGFILE
sleep $TIME
ps -A | grep "mplayer" > /dev/null 2>&1 #Replace with your own software
if [ $? -eq 0 ] ; then
PROGA_CHK=0
echo "`date` Mplayer is running" >> $LOGFILE
else
PROGA_CHK=1
echo "`date` Mplayer is not running." >> $LOGFILE
fi
ps -A | grep "gxine" > /dev/null 2>&1
if [ $? -eq 0 ] ; then
PROGB_CHK=0
echo "`date` Gxine is running" >> $LOGFILE
else
PROGB_CHK=1
echo "`date` Gxine is not running." >> $LOGFILE
fi
MOUSE2=`cat /proc/interrupts | grep 12: | awk '{print $2}'`
echo "`date` MOUSE2 equals $MOUSE2" >> $LOGFILE
KEYB2=`cat /proc/interrupts | grep ' 1:' | awk '{print $2}'`
echo "`date` KEYB2 equals $KEYB2" >> $LOGFILE
CUPS2=`ls -g /var/cups/log/page_log | cut -d ' ' -f 4`
echo "`date` CUPS2 equals $CUPS2" >> $LOGFILE
if [ $MOUSE1 -eq $MOUSE2 -a $KEYB1 -eq $KEYB2 -a $CUPS1 -eq $CUPS2 -a $PROGA_CHK -eq 1 -a $PROGB_CHK -eq 1 ] ; then
echo "`date` shutdown -h now" >> $LOGFILE
echo "shutting down"
echo " poweroff "
sleep 2
exec /usr/X11R7/bin/wmpoweroff #off in X grafic mode
sleep 2
/sbin/poweroff #power off in text mode,if was not previous in X
exit
fi
echo "reluare ciclu $TIME"
done
#End of script |
################
and it started by script (startmouseup):
##############
| Code: | #!/bin/sh
case "$1" in
start)
echo " starting no activity mouse/keyboard/cups-> power off"
/usr/local/mouseup/mouseup&
;;
esac |
#############
both resize on path /usr/local/mouseup
and I make a link /usr/local/mouseup/startmouseup to /etc/init.d/ to be automatically started at boot up.I preferred not to boot from X win by putting link in /root/Startup directory, because maybe in future I shall disable Xwin, Xserver automatically launch, if I use computer from remote as LAN printer
|
|
Back to top
|
|
 |
amigo
Joined: 02 Apr 2007 Posts: 1759
|
Posted: Fri 20 Feb 2009, 14:14 Post subject:
|
|
Can you please edit your post to enclose the code in CODE tags?
|
|
Back to top
|
|
 |
Dougal

Joined: 19 Oct 2005 Posts: 2505 Location: Hell more grotesque than any medieval woodcut
|
Posted: Sat 21 Feb 2009, 07:12 Post subject:
|
|
I think I found a daft way to handle USB devices...
I'm not sure what will happen if you're using a hub and maybe my search in /sys could produce more than one result...
I also suspect there's a chance that if your mouse/keyboard is connected via a hub that also has some kind of drive (pendrive or external HD), there's a chance that there'll be some periodic interrupts as a result of that...
I'm including a script that checks both USB and PS/2. (I'm not sure if the indentation won't get messed up, so I'm including a gzipped copy of it, too.
_________________ What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind
|
|
Back to top
|
|
 |
thoase
Joined: 03 Apr 2009 Posts: 109 Location: Sweden
|
Posted: Thu 07 May 2009, 08:03 Post subject:
|
|
But, where is my "startup" folder?
I tried to put mouseup.sh in my home-folder where intrd.gz, vmlinux and *.sfs-files are. But it wasn't the right folder!!
|
|
Back to top
|
|
 |
ricstef
Joined: 01 Aug 2006 Posts: 52 Location: Woodstock, ON. Canada
|
Posted: Thu 07 May 2009, 10:30 Post subject:
Startup folder |
|
@thoase
| Quote: | | But, where is my "startup" folder? |
Try
/root/Startup
Hope that helps.
Richard
|
|
Back to top
|
|
 |
puttingau
Joined: 12 Jun 2009 Posts: 15
|
Posted: Sun 18 Oct 2009, 02:54 Post subject:
include network activity |
|
I modified this to take into account network activity, when another user is accessing the internet through internet connection sharing. This script sits on the gateway machine, and won't shutdown if there is another user accessing the internet through it. Thanks to all on this post, and those on http://ubuntuforums.org/archive/index.php/t-530973.html
| Quote: | #!/bin/bash
# /root/startup/mouseup (2008-11-24)
# A script for testing user activity on their mouse
# and shutting down if given programs (2) are not running
# and there has been no mouse activity for declared period
# off time. Run as root
TIME=31m #set time between checks, "m" suffix for minutes
LOGFILE=/home/pete/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 mouseup. 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
#find the value of RX received packets to compare later for network activity
RX=`/sbin/ifconfig eth1 | grep -m 1 RX | cut -d: -f2 | sed 's/ //g' | sed 's/errors//g'`
echo "Initial RX: " $RX >> $LOGFILE
#add 1000 bytes;If a new RX measurement later, is less than this, some real network activity would have occurred
T_RX=`expr $RX + 300`
echo "Threshold RX: " $T_RX >> $LOGFILE
sleep $TIME
ps -A | grep "mplayer" > /dev/null 2>&1 #Replace with your own software
if [ $? -eq 0 ] ; then
PROGA_CHK=0
echo "`date` Mplayer is running" >> $LOGFILE
else
PROGA_CHK=1
echo "`date` Mplayer is not running." >> $LOGFILE
fi
ps -A | grep "VirtualBox" > /dev/null 2>&1
if [ $? -eq 0 ] ; then
PROGB_CHK=0
echo "`date` VirtualBox is running" >> $LOGFILE
else
PROGB_CHK=1
echo "`date` VirtualBox is not running." >> $LOGFILE
fi
#now check if RX value has increased
NEW_RX=`/sbin/ifconfig eth1 | grep -m 1 RX | cut -d: -f2 | sed 's/ //g' | sed 's/errors//g'`
echo "NEW_RX: " $NEW_RX >> $LOGFILE
if [ $NEW_RX -gt $T_RX ] ; then
NETWORK_CHK=0
echo " NEW_RX > threshold, a network user exists. " >> $LOGFILE
else
NETWORK_CHK=1
echo " NEW_RX < threshold, no network activity. " >> $LOGFILE
fi
MOUSE2=`cat /proc/interrupts | grep 12: | awk '{print $2}'`
echo "`date` MOUSE2 equals $MOUSE2" >> $LOGFILE
echo "MOUSE1 " $MOUSE1 " MOUSE2 "$MOUSE2 " PROGA_CHK " $PROGA_CHK " PROGB_CHK "$PROGB_CHK " NETWORK_CHK " $NETWORK_CHK >> $LOGFILE
if [ $MOUSE1 -eq $MOUSE2 -a $PROGA_CHK -eq 1 -a $PROGB_CHK -eq 1 -a $NETWORK_CHK -eq 1 ] ; then
echo "`date` shutdown -h now" >> $LOGFILE
echo "shutting down"
#/usr/X11R7/bin/restartwm ---for testing purposes---
#/usr/X11R7/bin/wmpoweroff
shutdown -h now
exit
fi
done
#End of script
|
Thank you steel_j , suits my needs perfectly
|
|
Back to top
|
|
 |
rollo5
Joined: 07 Mar 2013 Posts: 1
|
Posted: Sat 11 May 2013, 07:21 Post subject:
all mouse support + network up and download |
|
Hallo,
this is my first post. Puppy Linux is great!
I modified the script. Now all mouses are recognized because the script checks the mouse activity by the coordinates. It also checks the TX received packets, so the PC waits for up or download to finish.
It checks every minute for testing, you should change it.
| Code: | #!/bin/bash
# /root/startup/mouseup (2008-11-24)
# A script for testing user activity on their mouse
# and network activity
# and shutting down if given programs (2) are not running
# and there has been no mouse activity
# and network activity for declared period
# off time. Run as root
TIME=1m #set time between checks, "m" suffix for minutes
#LOGFILE=/mnt/home/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 mouseup. 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
XP1=$(getcurpos | cut -d" " -f1)
YP1=$(getcurpos | cut -d" " -f2)
#echo "XP1=$XP1" >> $LOGFILE
#echo "YP1=$YP1" >> $LOGFILE
#echo "CURPOS1=$CURPOS1" >> $LOGFILE
#find the value of RX received packets to compare later for network activity
RX=`/sbin/ifconfig eth0 | grep -m 1 RX | cut -d: -f2 | sed 's/ //g' | sed 's/errors//g'`
#echo "Initial RX: " $RX >> $LOGFILE
#add 1000 bytes;If a new RX measurement later, is less than this, some real network activity would have occurred
T_RX=`expr $RX + 300`
#echo "Threshold RX: " $T_RX >> $LOGFILE
TX=`/sbin/ifconfig eth0 | grep -m 1 TX | cut -d: -f2 | sed 's/ //g' | sed 's/errors//g'`
T_TX=`expr $TX + 300`
sleep $TIME
ps -A | grep "mplayer" > /dev/null 2>&1 #Replace with your own software
if [ $? -eq 0 ] ; then
PROGA_CHK=0
#echo "`date` mplayer is running" >> $LOGFILE
else
PROGA_CHK=1
#echo "`date` mplayer is not running." >> $LOGFILE
fi
ps -A | grep "virtualbox" > /dev/null 2>&1
if [ $? -eq 0 ] ; then
PROGB_CHK=0
#echo "`date` virtualbox is running" >> $LOGFILE
else
PROGB_CHK=1
#echo "`date` virtualbox is not running." >> $LOGFILE
fi
#now check if RX value has increased
NEW_RX=`/sbin/ifconfig eth0 | grep -m 1 RX | cut -d: -f2 | sed 's/ //g' | sed 's/errors//g'`
#echo "NEW_RX: " $NEW_RX >> $LOGFILE
NEW_TX=`/sbin/ifconfig eth0 | grep -m 1 TX | cut -d: -f2 | sed 's/ //g' | sed 's/errors//g'`
if [ $NEW_RX -gt $T_RX ] ; then
NETWORK_CHK_RX=0
#echo " NEW_RX > threshold, a network user exists. " >> $LOGFILE
else
NETWORK_CHK_RX=1
#echo " NEW_RX < threshold, no network activity. " >> $LOGFILE
fi
if [ $NEW_TX -gt $T_TX ] ; then
NETWORK_CHK_TX=0
#echo " NEW_RX > threshold, a network user exists. " >> $LOGFILE
else
NETWORK_CHK_TX=1
#echo " NEW_RX < threshold, no network activity. " >> $LOGFILE
fi
XP2=$(getcurpos | cut -d" " -f1)
YP2=$(getcurpos | cut -d" " -f2)
if [ $XP1 -eq $XP2 -a $YP1 -eq $YP2 -a $PROGA_CHK -eq 1 -a $PROGB_CHK -eq 1 -a $NETWORK_CHK_RX -eq 1 -a $NETWORK_CHK_TX -eq 1 ] ; then
#echo "`date` shutdown -h now" >> $LOGFILE
#echo "shutting down"
#/usr/X11R7/bin/restartwm ---for testing purposes---
#/usr/X11R7/bin/wmpoweroff
wmpoweroff
exit
fi
done
#End of script |
I need this script for my self made server (printing and data transfer).
cheers
roland
|
|
Back to top
|
|
 |
|