Small sh "framework" to test some server responses
sh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mpd.sh 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #Copyright (C) 2016,2023 Weber Yann
  2. #
  3. #This program is free software; you can redistribute it and/or modify
  4. #it under the terms of the GNU General Public License as published by
  5. #the Free Software Foundation; either version 3 of the License, or
  6. #any later version.
  7. #
  8. #This program is distributed in the hope that it will be useful,
  9. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. #GNU General Public License for more details.
  12. #
  13. #You should have received a copy of the GNU General Public License
  14. #along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. check_mpc() {
  16. # check_mpc [$host [$port] ]
  17. # tests if you can contact an MPD server in a client way
  18. # returns the current state of the server
  19. host=$1
  20. port=$2
  21. if [ -z "$host" ]
  22. then
  23. host=127.0.0.1
  24. fi
  25. if [ -z "$port" ]
  26. then
  27. port=6600
  28. fi
  29. if echo "status" | nc -w 1 "$host" "$port" | head -1 | grep "^OK MPD"
  30. then
  31. success "MPD server can be contacted on $host:$port"
  32. status=$(echo "status" | nc -w 1 "$host" "$port" | grep "^state:"|cut -d: -f2)
  33. success "It's state is : $status"
  34. fi
  35. }