SHARE
TWEET

Untitled

a guest Jul 21st, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Usage ./updown.sh x.x.x.x
  4.  
  5. function hostUp() {
  6.     msg="\"$1 is UP\""
  7.     osascript -e "display notification ${msg} with title \"Host UP\""
  8. }
  9.  
  10. function hostDown() {
  11.     msg="\"$1 is DOWN\""
  12.     osascript -e "display notification ${msg} with title \"Host DOWN\""
  13. }
  14.  
  15.  
  16. function is_alive() {
  17.     ping -c 1 $1 > /dev/null
  18.     if [ $? -eq 0 ] ;then
  19.         result=1
  20.     else
  21.         result=0
  22.     fi
  23. }
  24.  
  25.  
  26. state=-1
  27.  
  28. for (( ; ; ))
  29. do
  30.     is_alive $1
  31.     if [ $result -ne $state ]; then
  32.         if [ $result -eq 1 ]; then
  33.             hostUp $1
  34.         else
  35.             hostDown $1
  36.         fi
  37.     fi
  38.     state=$result
  39.     sleep 10
  40. #    echo "infinite loops [ hit CTRL+C to stop]"
  41. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top