Guest User

Untitled

a guest
Jun 4th, 2014
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #!/bin/bash
  2. # Curl Script to pull statistics from client side. Dispay results in JSON Format
  3.  
  4. statistics () {
  5. local site=$1
  6. if [ $firstline -eq 1 ] ; then
  7. echo -e "\t,"
  8. fi
  9. firstline=1
  10.  
  11. echo -e "\t{"
  12. curl -w '
  13. \t\t"{#SITE}":"'$1'",
  14. \t\t"{#LOOKUPTIME}":"%{time_namelookup}",
  15. \t\t"{#CONNECTTIME}":"%{time_connect}",
  16. \t\t"{#PRETRANSFERTIME}":"%{time_pretransfer}",
  17. \t\t"{#STARTTRANSFERTIME}":"%{time_starttransfer}",
  18. \t\t"{#SIZEDOWNLOAD}":"%{size_download}",
  19. \t\t"{#SPEEDDOWNLOAD}":"%{speed_download}",
  20. \t\t"{#TOTALTIME}":"%{time_total}"
  21. \t}
  22. ' -o /dev/null -s $site
  23. #echo
  24.  
  25. }
  26.  
  27. firstline=0
  28. echo -e "{"
  29. echo -e "\t\"data\":["
  30.  
  31. ## declare an array variable with site links to meassure performance
  32. #declare -a arr=("http://www.google.com.au" "http://www.microsoft.com")
  33. arr=()
  34. # Read the file in parameter and fill the array named "array"
  35. getArray() {
  36. i=0
  37. while read line # Read a line
  38. do
  39. arr[i]=$line # Put it into the array
  40. i=$(($i + 1))
  41. done < $1
  42. }
  43. getArray "/opt/zabbix/sites.txt"
  44.  
  45. #for i in ${@}; do
  46. for i in "${arr[@]}"; do
  47. statistics $i
  48. done
  49.  
  50. echo -e "\t]"
  51. echo -e "}"
Advertisement
Add Comment
Please, Sign In to add comment