Blondie wrote: 
> What should i enter or do here?
Somethin' ElseĀ…

1st off, I think you are confusing the return value of a command and a
value printed on the standard output. You may want to check on that.
2nd, AFAIK ServerPowerControl offers a launcher for a custom script. It
does not look for what the script prints out to take an action. In your
case, what this means is your script has to 1. detect logins, AND 2.
block/release sleep accordingly.

Since you started using the shell, I thought I'd dust off my bash skills
and write a bit of script that does, hopefully, what you want:
Code:
--------------------
    #!/bin/bash
  #set -x 
  HOST=127.0.0.1
  PORT=9090
  NETCAT="/bin/nc -w 1 $HOST $PORT"
  ME="loginchecker"
  
  getlogins() {
        LOGINS=`who|wc -l`
        LOGINS=`expr $LOGINS \* 1` # Now a number
        #echo "Got: $LOGINS logins" 
  }
  
  getblocks() {
        CMD="srvrpowerctrl listblock"
        BLOCKS=`echo $CMD|$NETCAT` 
        # Returns something like this [srvrpowerctrl listblock  
255630%7Cnotbyme%7Csomereason 568864%7Cloginchecker%7Cbusy 
496120%7Cloginchecker%7Cbusy]
        # Remove echoed command
        BLOCKS=${BLOCKS##$CMD}
        # Count blocks returned
        # BLOCKCOUNT=`echo $BLOCKS|wc -w`
        # echo  "Existing blocks: $BLOCKCOUNT"
        # Count blocks owned by $ME
        MEBLOCKCOUNT=0
        for BLOCK in $BLOCKS; do
                [[ "$BLOCK" == *$ME* ]] && let MEBLOCKCOUNT++
        done
        # echo "Blocks placed by $ME: $MEBLOCKCOUNT"
  }
  
  getlogins
  getblocks
  
  case $LOGINS in 
  
  0)     # Nobody logged in. Sleeping should be ok. 
        # Release blocks created by $ME
        for BLOCK in $BLOCKS; do
                if [[ "$BLOCK" == *$ME* ]]; then
                # Grab block ID
                ID=${BLOCK%%'%7C'*}
                CMD="srvrpowerctrl clearblock $ID $ME"
                # Silently destroy the block
                echo $CMD|$NETCAT > /dev/null 2>&1
                fi
        done
        ;;
  
  *)     # Any other value. Don't sleep. 
        # Place a block unless $ME already owns one
        if [[ "$MEBLOCKCOUNT" -eq 0 ]]; then 
                CMD="srvrpowerctrl setblock busy $ME"
                # Silently place the block
                echo $CMD|$NETCAT > /dev/null 2>&1
        fi
        ;;
  esac
  exit 0
  
--------------------
 
This script uses the powers of Server Power Control's CLI. Than makes it
dependent on netcat. Also, it doesn't use the newer way of blocking
sleep, which is by creating/removing a /var/lock/spc-block file,
(AFAIK), making the code a bit more complex. In exchange, it should be
sophisticated enough not to destroy blocks that may have been set by
other plugins/external scripts. 

I have checked this code against SBS 7.6.2 and Server Power Control
v20090615.00. You are probably using the beta version (20111028.140356),
which is certainly advisable. I recommend you check all is ok by running
the script from the command-line with "set -x" enabled. Have a look at
ServerPowerControl's readme and whatsnew files for any changes needed to
the CLI commands.

Have fun


------------------------------------------------------------------------
epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711
View this thread: http://forums.slimdevices.com/showthread.php?t=48521

_______________________________________________
plugins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/plugins

Reply via email to