#!/bin/sh # zeroloadoff autopoweroff when load zero # Must run by root (halt/poweroff) # # 0.01 6/1/2003 first version (autopoweroff reduced) # 0.02 9/2/2003 sleep 30 before check # 0.03 16/2/2003 knoppix & all in "en" #------------------------------------------------------------------------------ function message () { echo "`date '+%b %d %H:%M:%S'` autopoweroff: $*" logger -p daemon.info -t zeroloadoff -- "$*" # Send to daemon.log } message "monitorizing loadavg..." # ENDLESS LOOP while true do # WAIT BEFORE CHECK/RETRY sleep 30 # WAIT FAST LOAD AVG == ZERO if [ "`awk '{print $1}' /proc/loadavg`" == "0.00" ] then break fi message "Not yet... `cat /proc/loadavg`" done # LETS POWEROFF message "loadavg==0.00 Poweroff system" # KNOPPIX FROM CD does not really poweroff so we have to do it by hand... if [ -e /KNOPPIX/bin/ash ] then echo "Sending processes the TERM signal" killall5 -15 sleep 5 echo "Sending processes the KILL signal" killall5 -9 echo "Unmounting file systems" swapoff -a umount -arvf #rmmod -a echo "" echo "POWER OFF" halt -fp # Really poweroff fi poweroff #sudo /sbin/poweroff # Use sudo for no root users # NO POWEROFF ! sleep 30 message "WARNING: PC can not selfpoweroff..." message " - Or you have not permissions for poweroff" message " - Or apm support is not active" message " - Or there is not apm support in kernel (recompile it)"