OLD | NEW |
(Empty) | |
| 1 #!/bin/sh |
| 2 # |
| 3 # Port control script for Digital Loggers Inc. Web Power Switch II and III |
| 4 # |
| 5 # Written by: Grant Likely <grant.likely@secretlab.ca> |
| 6 # Copyright 2010 Secret Lab Technologies Ltd. |
| 7 # |
| 8 # Usage: dli-pscontrol.sh <admin:passwd@host> <port> {on|off|cycle} |
| 9 # |
| 10 # <port> is in the range 1..8. |
| 11 # 'cycle' will turn a port off and on with a 1 second delay. |
| 12 # |
| 13 # The Web Power Switch uses a simple http request protocol for controlling |
| 14 # the port state. The action simply gets encoded into the url in the form: |
| 15 # |
| 16 # http://<user>:<passwd>@<host[:port]>/outlet?<port-number>={ON|OFF|CCW} |
| 17 # |
| 18 # ON and OFF are self explanatory. |
| 19 # CCW means cycle power, but only has effect when the port is already on. |
| 20 # |
| 21 # The protocol is simple enough that wget is sufficient to control ports. |
| 22 |
| 23 baseurl="http://${1}" |
| 24 porturl="${baseurl}/outlet?${2}" |
| 25 |
| 26 wget_cmd="wget --auth-no-challenge -O /dev/null" |
| 27 |
| 28 port_set() { |
| 29 ${wget_cmd} "${porturl}=${1}" > /dev/null 2>&1 |
| 30 } |
| 31 |
| 32 case "$3" in |
| 33 on) |
| 34 port_set ON |
| 35 ;; |
| 36 off) |
| 37 port_set OFF |
| 38 ;; |
| 39 cycle) |
| 40 # The CCW command *could* be used here, but the command has no |
| 41 # effect if the port is in the OFF state. |
| 42 port_set OFF |
| 43 sleep 1s |
| 44 port_set ON |
| 45 ;; |
| 46 *) |
| 47 echo "Usage: $0 <admin:passwd@host> <port> {on|off|cycle}" |
| 48 exit 1; |
| 49 ;; |
| 50 esac |
| 51 |
| 52 exit 0 |
OLD | NEW |