Advertisement
funcelot

ping_site.sh

Feb 9th, 2020
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.39 KB | None | 0 0
  1. #!/bin/bash -e
  2. ping_cancelled=false    # Keep track of whether the loop was cancelled, or succeeded
  3. until ping -c1 "$1" >/dev/null 2>&1; do :; done &    # The "&" backgrounds it
  4. trap "kill $!; ping_cancelled=true" SIGINT
  5. wait $!          # Wait for the loop to exit, one way or another
  6. trap - SIGINT    # Remove the trap, now we're done with it
  7. echo "Done pinging, cancelled=$ping_cancelled"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement