2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 10:46:53 +00:00
rudolfkoenig 4205850e95 Martins getstate added
git-svn-id: https://svn.fhem.de/fhem/trunk@307 2b470e98-0d58-463d-a4d8-8e2adae1ed80
2008-12-28 14:43:45 +00:00

83 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
#
# fhem-getstate script for reading / writing DigiTemp values
# Copyright (C) 2008 Martin Fischer <m_fischer@gmx.de>. All rights reserved.
#
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This source is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
NCAT=`which netcat`
HOST="localhost"
PORT="7072"
# Functions
function version {
echo "fhem-getstate, Version 1.0
Copyright (C) 2008 Martin Fischer <m_fischer@gmx.de>
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Martin Fischer"
exit $1
}
function longhelp {
echo "\
Usage: fhem-getstate [OPTION] DEVICE
Connect to a FHEM-Server running on 'localhost 7072' and print the status for
the given DEVICE as a space seperated list for use in e.g. Cacti.
Mandatory arguments:
-d DEVICE print the status for DEVICE as defined in FHEM
Optional:
-s SERVER Resolvable Hostname or IP address of FHEM (default: localhost)
-p PORT Listening Port of FHEM (default: 7072)
-q quiet mode
-h show this help
-v show version
Reports bugs to <m_fischer@gmx.de>.
"
exit $1
}
function usage {
echo >&2 "Usage: fhem-getstate [-s <server>] [-p <port>] -d <devspec> [-h] [-v]" && exit $1;
}
# check for arguments
if (( $# <= 0 )); then
usage 1;
fi
# get options
while getopts "s:p:d:hv" option; do
case $option in
d) DEV=$OPTARG;;
h) longhelp 0;;
p) PORT=$OPTARG;;
s) HOST="$OPTARG";;
v) version 0;;
?) usage 1;;
esac
done
(echo "getstate ${DEV}" | $NCAT -w1 ${HOST} ${PORT})
exit 0;