Skip to content

Instantly share code, notes, and snippets.

@dawehner
Created April 29, 2014 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dawehner/11393594 to your computer and use it in GitHub Desktop.
Save dawehner/11393594 to your computer and use it in GitHub Desktop.
Provide a small script to check whether a host is reachable via ssh, when the ssh connection is disabled/storage problems occured or whatever
import subprocess
import os
proc = subprocess.Popen(['ssh', '-v', 'user@host', 'exit'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for line in iter(proc.stderr.readline,''):
if line.find("Authenticated to") is not -1:
os.system('notify-send "Server X works again"');
os.system('echo "Server X works again" | mail -s "Server update" yourmail@example.com')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment