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.

example.sh 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/sh
  2. usage() {
  3. echo "Usage : $0 [OPTIONS]
  4. -h --help : display this help and exit
  5. -c --continue : continue after a failure
  6. -n --no-color : disable uses of tput to display colors
  7. -v --verbose : increase verbosity level"
  8. }
  9. verbose=0
  10. exit_on_fail=1
  11. color=1
  12. if OPTS=$(getopt -o vcnh --long verbose,continue,no-color,help: -n 'parse-options' -- "$@")
  13. then
  14. :
  15. else
  16. echo ""
  17. usage
  18. exit 1
  19. fi
  20. for o in $OPTS
  21. do
  22. case "$o"
  23. in
  24. -v | --verbose ) verbose=$(( verbose + 1 ));;
  25. -c | --continue ) exit_on_fail=0;;
  26. -n | --no-color ) color=0;;
  27. -h | --help ) usage; exit 0;;
  28. -- ) break;;
  29. *) echo "Unknown argument '$1'" >&2;
  30. usage
  31. exit 1;;
  32. esac
  33. done
  34. export color
  35. export verbose
  36. export exit_on_fail
  37. . ./check.sh
  38. # Initialize tests
  39. CHECK_START
  40. # Init testcase with title and description
  41. TC_INIT "Ping check" "Send ping to some hosts" # Needs ping
  42. TC_RUN check_ping gnu.org 2
  43. TC_RUN check_ping localhost
  44. TC_END
  45. TC_INIT "SSH" "Testing ssh server" # Needs netcat
  46. TC_RUN check_ssh_nc ssh.cluster007.ovh.net
  47. TC_RUN check_ssh_key ssh.cluster007.ovh.net 'AAAAB3NzaC1yc2EAAAADAQABAAACAQCvCBGdzkE/BJV+TcDGXJ+ypb5B035EjZhFOrsHi6RaY1wRuR2uhs/4QfDs4VcT/yWLD/W7ud5V+WNoWirpvq21MjYnu4Iykj7H1GRuAcUrqordUV8M8xrwzDbB1V9pbCTBQ37OZqnVVliF6va3GnNsbhqeF6BABEf3cdSk/ocQ8He0duU6w6cIXm8WsQU+KmKFdGhiTa4vxbc/78HYKStmo6wXXlVfjyVOqpIUk+RXpk5iDDYIb0mulGhP0Dx50ot8tVi21qdkE06+RXKbiUtiWoKyclJSD/dmp0Ku0MIVo2gDOj1pePuT7hGBYiXXHF0n8gKLZ1NGWO/xaOrz/GUx1wWPdQEAufsXwkBU3at3YPYbMEt4iesRMRXgx4jCBwdQgrcKOXKj1h5uSinwT5WodvsmUwqqeYhPMp2SeWHUKyDtNsrI/sd38uMfgK9AouIQcdlDzE9Toinp6++41jQYpuArGUzE88AG0A0j5BgRzz3RGXukxZJBtjYx4TJW/qUg95lHOPihyQBoMW/N5ZooHyr0ZuvXVK5JGyCIk6H04CsRDC9kCkAXD/mi1MjiKBdCShE4YwrNneixKGPC+LgkgyNwuQnrCxqlsaniMANuZ9vVx/vY935/oAi40DIuO+/WUyvs0i5l14EJUr/mOPA72CT/mRc5D4Q4GC1hjypHuw=='
  48. TC_END
  49. TC_INIT "HTTP/HTTPS" "Testing HTTP status & HTTPS cert" # Needs curl
  50. TC_RUN check_https_cert gnu.org
  51. TC_RUN check_http_200 http://www.gnu.org/home.html
  52. TC_RUN check_http_status http://www.gnu.org/sqdsqdk.foo 404
  53. TC_RUN check_http_status http://gnu.org/ 301
  54. TC_END
  55. TC_INIT "HTML" # Needs xsltproc
  56. TC_RUN check_html_title http://www.gnu.org/ "The GNU Operating System and the Free Software Movement"
  57. TC_END
  58. TC_INIT "Git" "Try to clone a git repo" # Needs git
  59. TC_RUN check_git_repo https://git.yannweb.net/yannweb/mhssh.git
  60. TC_END
  61. TC_INIT "Audio streaming" "Testing audio stream" # Needs mplayer
  62. TC_RUN check_audiostream http://zmpd.zered.net:8042/fip-metadata.mp3
  63. TC_RUN check_audiostream http://ice1.somafm.com/missioncontrol-128-mp3 256kb
  64. TC_END
  65. # Display results
  66. CHECK_REPORT