fhem-getstate 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. #
  3. # $Id: fhem-getstate,v 1.2 2009-01-12 09:21:53 rudolfkoenig Exp $
  4. #
  5. # Copyright notice
  6. #
  7. # (c) 2008 Copyright: Martin Fischer (m_fischer at gmx dot de)
  8. # All rights reserved
  9. #
  10. # This script free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # The GNU General Public License can be found at
  16. # http://www.gnu.org/copyleft/gpl.html.
  17. # A copy is found in the textfile GPL.txt and important notices to the license
  18. # from the author is found in LICENSE.txt distributed with these scripts.
  19. #
  20. # This script is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU General Public License for more details.
  24. #
  25. ################################################################
  26. NCAT=`which netcat`
  27. HOST="localhost"
  28. PORT="7072"
  29. VERS="$Revision: 1.2 $"
  30. # Functions
  31. function version {
  32. echo "fhem-getstate, Version$VERS
  33. Copyright (C) 2008 Martin Fischer <m_fischer@gmx.de>
  34. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  35. This is free software: you are free to change and redistribute it.
  36. There is NO WARRANTY, to the extent permitted by law.
  37. Written by Martin Fischer"
  38. exit $1
  39. }
  40. function longhelp {
  41. echo "\
  42. Usage: fhem-getstate [OPTION] DEVICE
  43. Connect to a FHEM-Server running on 'localhost 7072' and print the status for
  44. the given DEVICE as a space seperated list for use in e.g. Cacti.
  45. Mandatory arguments:
  46. -d DEVICE print the status for DEVICE as defined in FHEM
  47. Optional:
  48. -s SERVER Resolvable Hostname or IP address of FHEM (default: localhost)
  49. -p PORT Listening Port of FHEM (default: 7072)
  50. -q quiet mode
  51. -h show this help
  52. -v show version
  53. Reports bugs to <m_fischer@gmx.de>.
  54. "
  55. exit $1
  56. }
  57. function usage {
  58. echo >&2 "Usage: fhem-getstate [-s <server>] [-p <port>] -d <devspec> [-h] [-v]" && exit $1;
  59. }
  60. # check for arguments
  61. if (( $# <= 0 )); then
  62. usage 1;
  63. fi
  64. # get options
  65. while getopts "s:p:d:hv" option; do
  66. case $option in
  67. d) DEV=$OPTARG;;
  68. h) longhelp 0;;
  69. p) PORT=$OPTARG;;
  70. s) HOST="$OPTARG";;
  71. v) version 0;;
  72. ?) usage 1;;
  73. esac
  74. done
  75. (echo "getstate ${DEV}" | $NCAT -w1 ${HOST} ${PORT})
  76. exit 0;