..
System Administration Python Script
Being a System Administrator one of the best tools you can possibly have at your arsenal is Python. Python is a lightweight language that has numerous advantages such as being simple to write and has an OS module containing access to numerous direct Linux OS API’s.
With Python you can easily test a connection to a server using the ‘Server’ module. Below is a simple implementation:
#!/usr/bin/env python
import socket
import time
HOST=""
PORT=""
TIMEOUT=1.0
while True:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(TIMEOUT)
s.connect((HOST, PORT))
print "[%s] Connection established" % time.strftime("%H:%M:%S")
time.sleep(1)
s.close()
except:
print "[%s] Cannot connect" % time.strftime("%H:%M:%S")
Happy Coding,
-Korben