Having some fun with a Raspberry Pi, setting up a little Python script to run a ping, and if it fails, send me an email via gmail - I'm a novice in Python, but using google-fu I was able to do just that (and I have full understanding of how this is working).
What I'd like to achieve, is be able to use a list (in a txt file) where I can have either by line or CSV, a list of hosts to run the script on .
host = "histname.com"
debuglevel = 0
server = smtplib.SMTP('smtp.gmail.com:587')
subj = "Network Down", host
date = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" )
msg = "From: %s\nTo: %s\nSubject: %s\n Date: %s\n%s" % ( from_addr, to_addr, subj, date, message_text )
server.sendmail(from_addr, to_addr, msg)
result = os.system("ping -c 5 %s" %(ipaddress))
ip = host
if result != 0:
print ('Ping failed', host)
mess = ("Is Down", host)
mess= ("Mesasge Body 2")
ictr += 1
print ('Ping Ok !')
Note this is mostly for fun - I quickly built the same for powershell, but if I could get this to work the same on a raspberry pi...