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.

net.sh 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_ping() {
  16. hostname=$1
  17. count=$2
  18. proto="$3"
  19. if [ -z "$count" ]
  20. then
  21. count=5
  22. fi
  23. case "$proto" in
  24. ipv4)
  25. protoping="ping -4";;
  26. ipv6)
  27. protoping="ping -6";;
  28. *)
  29. protoping="ping";;
  30. esac
  31. if $protoping -i 0.2 -c "$count" "$hostname" >/dev/null
  32. then
  33. success "successfully send $count ping to '$hostname'"
  34. else
  35. fail "unable to ping '$hostname'"
  36. fi
  37. }
  38. check_dns() {
  39. hostname=$1
  40. field=$2
  41. expt=$3
  42. result=$(dig +short "$hostname" "$field")
  43. if echo "$result" | grep -e "$expt" >/dev/null
  44. then
  45. success "DNS replied '$expt' for '$field $hostname'"
  46. else
  47. fail "Unexpected DNS reply '$result' expecting '$expt' for '$hostname $field'"
  48. fi
  49. }