Test script if host is back online

Posted by brubelsabs on Super User See other posts from Super User or by brubelsabs
Published on 2010-10-15T07:21:11Z Indexed on 2010/12/25 11:55 UTC
Read the original article Hit count: 270

Filed under:
|
|
|

E.g. system: Ubuntu/Debian.

As many of you do this probably via ping and a terminal, I always forget this terminal when switching to other task... So a noftification popup would be useful. So can I do better as this?:

while; do
  if ping -c 1 your.host.com; expr $? = 0; then
     notify-send "your.host.com back online"; sleep 30s;
  else
     sleep 30s;
  fi;
done

You will need zsh and libnotify to let the snippet work. As script:

#!/usr/bin/env zsh
while; do if ping -c 1 $1; expr $? = 0; then notify-send "$1 back online"; sleep 30s; else sleep 30s; fi; done

© Super User or respective owner

Related posts about linux

Related posts about notifications