[NTLUG:Discuss] Script request
Carl Haddick
sysmail at glade.net
Mon Mar 2 15:32:53 CST 2009
On Mon, Mar 02, 2009 at 02:26:17PM -0600, imageek72 at gmail.com wrote:
>
> On Mon, Mar 2, 2009 at 2:21 AM, Fred <fredstevens at yahoo.com> wrote:
> >Has anyone got a script that cron could run to see if
> >a server is up and running? I just found out that a webserver
> >over in the corner has been sitting there for 4 days waiting
> >for someone to get the driver CD out of the drive and let
> >it boot. This was after the power company ran down the
> >battery in the UPS unit. (well, not really, but you know...)
> >
> >I guess a simple ping test would work, since if it is up enough
> >for the networking, then the rest is probably running, too.
> >That would be better than now, which is nothing.
>
>
Nagios, as recommended elsewhere, is a good thing - I monitor a bunch of
stuff with it.
But for a simple cron script, here's something completely different:
=====
#!/usr/local/bin/python
import telnetlib,sys
if len(sys.argv)!=3:
print 'Usage - tcpcheck <host> <port>'
sys.exit()
t=telnetlib.Telnet()
try:
t.open(sys.argv[1],int(sys.argv[2]))
t.close()
except:
print 'Connection failed'
sys.exit(1)
sys.exit
=====
That will return a 0 to the shell for a successful connection, one
otherwise. Usage is of the form:
./tcpcheck.py www.yahoo.com 80'
Good day!
Carl
More information about the Discuss
mailing list