Advertisement
Guest User

Bash HttpPing

a guest
Aug 24th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.73 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function pingSite {
  4.     site=$1
  5.     timeInSeconds="$(curl -o /dev/null -s -w %{time_total}\\n $site)"
  6.     timeInMs=$(echo $timeInSeconds | sed -r 's/([0-9]+)\.([0-9]+)/\1\2ms/' | sed -r 's/0*([0-9]+)/\1/')
  7.     echo $timeInMs;
  8. }
  9.  
  10. function getAndOutputSitePing {
  11.     site=$1
  12.     siteTime=$(pingSite $site)
  13.     printf "$site: $siteTime "
  14. }
  15.  
  16. baseSite='http://www.google.com'
  17.  
  18. if [[ -z "$1" ]]; then
  19.     printf "You can specify a site to ping with:\nhttpping http://mysite.com\n\n"
  20.     echo "Defaulting to pinging $baseSite every 1 second"
  21. else
  22.     baseSite=$1
  23.     echo "Pinging $baseSite every 1 second"
  24. fi
  25.  
  26. printf "Press ctrl+c to cancel\n\n"
  27.  
  28. echo "Time taken:"
  29.  
  30. while true; do
  31.     getAndOutputSitePing $baseSite
  32.  
  33.     printf "\n"
  34.     sleep 1
  35. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement