Changeset 362 for misc/power-saver
- Timestamp:
- Feb 13, 2012, 9:32:02 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
misc/power-saver
r361 r362 19 19 MAX_IDLE=60 20 20 21 # Abuse this trick to force a quicker shutdown by ignoring some users 22 IDLE_USER=${1:-1} 23 SHUTDOWN_DELAY=${2:-15} 24 21 25 # Stored as <epoch> <load> 22 26 DAT_FILE='/tmp/power-saver.dat' … … 33 37 34 38 # Check if all users are no longer active 35 SHORTEST_IDLE=`w -ih | awk '{print $5}' | head -1`39 SHORTEST_IDLE=`w -ih | awk -vIDLE_USER=$IDLE_USER '{if (NR == IDLE_USER) print $5}'` 36 40 # Hack to make sure time is always in minutes 37 41 SHORTEST_IDLE_IN_MIN=`echo $SHORTEST_IDLE | awk -F: '{if (NF > 1){print $1 * 60 + $2}else{print $1}}'` … … 49 53 # Count the amount entries we are current on our way 50 54 IDLE_COUNTS=`awk -vMAX_LOAD=$MAX_LOAD -vMAX_IDLE=$MAX_IDLE -vEPOCH=$EPOCH \ 51 'BEGIN{MIN_TIME=EPOCH-MAX_IDLE;s=0}{if ($1 > MIN_TIME && $2 >MAX_LOAD){s += 1}}END{print s}' $DAT_FILE`55 'BEGIN{MIN_TIME=EPOCH-MAX_IDLE;s=0}{if ($1 > MIN_TIME && $2 < MAX_LOAD){s += 1}}END{print s}' $DAT_FILE` 52 56 53 57 # We are idle for over $MAX_IDLE time, starting shutdown 54 58 if [ $IDLE_COUNTS -gt `expr $MAX_IDLE / $CRON_INTERVAL` ]; then 55 echo shutdown -p "+ 15" "Cancel: sudo killall -SIGTERM shutdown"59 echo shutdown -p "+$SHUTDOWN_DELAY" "Cancel: sudo killall -SIGTERM shutdown" 56 60 fi
Note:
See TracChangeset
for help on using the changeset viewer.