Monitoring SSHd and web servers?

Pacman nomailplease at sonic.net
Fri Mar 14 14:13:57 EDT 2008


Gilles Ganault <nospam at nospam.com> wrote:
>I'd like to monitor connections to a remote SSH and web server. Does
>someone have some code handy that would try to connect every 5mn, and
>print an error if the script can't connect?

This script has been pretty reliable for us for the past few years,
much more reliable than the expect script it replaced.

  #!/usr/bin/python
  import sys
  import pexpect 
  quiet = open("/dev/null", "rw")
  sys.stdin = quiet
  sys.stdout = quiet
  sys.stderr = quiet 
  smtp = pexpect.spawn("telnet " + sys.argv[1] + " 25")
  smtp.expect('220', timeout=120)
  smtp.sendline("quit\n^]q")

Pacman



More information about the Python-list mailing list