Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement