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.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. OPTS=$(getopt -o vcnh --long verbose,continue,no-color,help: -n 'parse-options' -- "$@")
  13. if [ "$?" -ne "0" ]
  14. then
  15. echo ""
  16. usage
  17. exit 1
  18. fi
  19. for o in $OPTS
  20. do
  21. case "$o"
  22. in
  23. -v | --verbose ) verbose=$(expr $verbose + 1);;
  24. -c | --continue ) exit_on_fail=0;;
  25. -n | --no-color ) color=0;;
  26. -h | --help ) usage; exit 0;;
  27. -- ) break;;
  28. *) echo "Unknown argument '$1'" >&2;
  29. usage
  30. exit 1;;
  31. esac
  32. done
  33. export color
  34. export verbose
  35. export exit_on_fail
  36. . ./check.sh
  37. # Initialize tests
  38. CHECK_START
  39. # Init testcase with title and description
  40. TC_INIT "Ping check" "Send ping to some hosts" # Needs ping
  41. TC_RUN check_ping gnu.org 2
  42. TC_RUN check_ping localhost
  43. TC_END
  44. TC_INIT "SSH" "Testing ssh server" # Needs netcat
  45. TC_RUN check_ssh_nc ssh.cluster007.ovh.net
  46. TC_RUN check_ssh_key ssh.cluster007.ovh.net 'AAAAB3NzaC1yc2EAAAADAQABAAABAQCxTdeGLZ7JYXj6XbxlRSK5YXxfgD3HMmaXFtsM+jMZXKAVG6wLBTaLS3CqhUbtuFNs/or6geS1tban33x2nyGn283Wbf3x1PS1cgg9fBAd9tQNsZZ7pEJ6shqv4Lnv+cHRdgNPrGnEim/eUs3H7ZOd5CuCpaoDV31XD+klwCAu/ANq+GiX4iarER59Ij6xd736r+kYAWbguZCV0lL91ag5g6+vVvufHngr6HY5rvl1Ybw1nSfzEG4+UYl5EwvWFSuxPq706DV1kUDmQ17GkD/z0GzBdPDMzgQSLEVvT3CBqAqrosGZO2Iap8EOLDBd/h6ZWWsO2EjEadJJXb23xwhr'
  47. TC_END
  48. TC_INIT "HTTP/HTTPS" "Testing HTTP status & HTTPS cert" # Needs curl
  49. TC_RUN check_https_cert gnu.org
  50. TC_RUN check_http_200 http://www.gnu.org/index.html
  51. TC_RUN check_http_status http://www.gnu.org/sqdsqdk.foo 404
  52. TC_RUN check_http_status http://gnu.org/ 301
  53. TC_END
  54. TC_INIT "HTML" # Needs xsltproc
  55. TC_RUN check_html_title http://www.gnu.org/ "The GNU Operating System and the Free Software Movement"
  56. TC_END
  57. TC_INIT "Git" "Try to clone a git repo" # Needs git
  58. TC_RUN check_git_repo https://git.yannweb.net/yannweb/mhssh.git
  59. TC_END
  60. TC_INIT "Audio streaming" "Testing audio stream" # Needs mplayer
  61. TC_RUN check_audiostream http://zmpd.zered.net:8042/fip-metadata.mp3
  62. TC_RUN check_audiostream http://ice1.somafm.com/missioncontrol-128-mp3 256kb
  63. TC_END
  64. # Display results
  65. CHECK_REPORT