Created
April 12, 2012 20:23
-
-
Save urbans/2370734 to your computer and use it in GitHub Desktop.
Server status via email (python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
import commands | |
# Email details | |
from_address = 'Status reporter<my.status.reporter@gmail.com>' | |
to_address = 'recipient@gmail.com' | |
message_subject = "My server daily report" | |
# Credentials | |
username = 'my.status.reporter@gmail.com' | |
password = '*******' | |
# Assemble message | |
msg_body = commands.getoutput('df -h') + "\r\n\r\n" + "Uptime: " + commands.getoutput('uptime') + "\r\nDate: " + commands.getoutput("date") + "\r\n\r\n" | |
message = "From: %s\r\n" % from_address + "To: %s\r\n" % to_address + "Subject: %s\r\n" % message_subject + "\r\n" + msg_body | |
# Send mail | |
server = smtplib.SMTP('smtp.gmail.com:587') | |
server.ehlo() | |
server.starttls() | |
server.ehlo() | |
server.login(username,password) | |
server.sendmail(from_address, to_address, message) | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment