Changeset 362 for misc/power-saver


Ignore:
Timestamp:
Feb 13, 2012, 9:32:02 PM (13 years ago)
Author:
Rick van der Zwet
Message:

Allow hacking on CLI by introducing some variables.

Load off-course needs to be less not more.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • misc/power-saver

    r361 r362  
    1919MAX_IDLE=60
    2020
     21# Abuse this trick to force a quicker shutdown by ignoring some users
     22IDLE_USER=${1:-1}
     23SHUTDOWN_DELAY=${2:-15}
     24
    2125# Stored as <epoch> <load>
    2226DAT_FILE='/tmp/power-saver.dat'
     
    3337
    3438# Check if all users are no longer active
    35 SHORTEST_IDLE=`w -ih | awk '{print $5}' | head -1`
     39SHORTEST_IDLE=`w -ih | awk -vIDLE_USER=$IDLE_USER '{if (NR == IDLE_USER) print $5}'`
    3640# Hack to make sure time is always in minutes
    3741SHORTEST_IDLE_IN_MIN=`echo $SHORTEST_IDLE | awk -F: '{if (NF > 1){print $1 * 60 + $2}else{print $1}}'`
     
    4953# Count the amount entries we are current on our way
    5054IDLE_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`
    5256
    5357# We are idle for over $MAX_IDLE time, starting shutdown
    5458if [ $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"
    5660fi
Note: See TracChangeset for help on using the changeset viewer.