0x0049

up

Jul 22nd, 2015
378
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.52 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function loop-until-up() {
  4.     until nmap -sn $1 | grep "Host is up" > /dev/null ; do
  5.         sleep 5s
  6.     done
  7. }
  8.  
  9. function alarm-while-up() {
  10.     while nmap -sn $1 | grep "Host is up" > /dev/null ; do
  11.         printf '\7'
  12.         sleep 2s
  13.     done
  14. }
  15.  
  16. function main() {
  17.     echo Waiting for $1...
  18.     loop-until-up $1
  19.  
  20.     echo -n $1 went UP at
  21.     date +" %H:%M, %a, %m/%d/%g"
  22.  
  23.     alarm-while-up $1
  24.  
  25.     echo -n $1 went back down at
  26.     date +" %H:%M, %a, %m/%d/%g"
  27.     main $1
  28. }
  29.  
  30. if [ -z $1 ] ; then
  31.     echo Missing IP address
  32. else
  33.     main $1
  34. fi
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment