Created
May 24, 2012 23:22
-
-
Save AhnSeongHyun/2784849 to your computer and use it in GitHub Desktop.
send email with pstack.log file
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 | |
from email.MIMEMultipart import MIMEMultipart | |
from email.MIMEBase import MIMEBase | |
from email.MIMEText import MIMEText | |
from email import Encoders | |
import os | |
import socket | |
import time | |
gmail_user = "sh84.ahn@gmail.com" | |
gmail_pwd = "xxxxx" | |
def mail(to, subject, text, attach): | |
msg = MIMEMultipart() | |
msg['From'] = gmail_user | |
msg['To'] = to | |
msg['Subject'] = subject | |
msg.attach(MIMEText(text)) | |
part = MIMEBase('application', 'octet-stream') | |
part.set_payload(open(attach, 'rb').read()) | |
Encoders.encode_base64(part) | |
part.add_header('Content-Disposition', | |
'attachment; filename="%s"' % os.path.basename(attach)) | |
msg.attach(part) | |
mailServer = smtplib.SMTP("smtp.gmail.com", 587) | |
mailServer.ehlo() | |
mailServer.starttls() | |
mailServer.ehlo() | |
mailServer.login(gmail_user, gmail_pwd) | |
mailServer.sendmail(gmail_user, to, msg.as_string()) | |
# Should be mailServer.quit(), but that crashes... | |
mailServer.close() | |
sec = 5 | |
while 1: | |
time.sleep(sec); | |
file_list = os.listdir("./"); | |
pstack_count = 0; | |
pstack_list =[]; | |
for file in file_list: | |
count = file.count("pstack"); | |
if count >0: | |
pstack_list.append(file); | |
pstack_count += count; | |
if pstack_count >0: | |
server_name = socket.gethostname(); | |
for file in pstack_list: | |
mail("sh84.ahn@gmail.com",server_name + "::pstack log", file, "./"+file); | |
print "["+file+"]"+" send to sh84.ahn@gmail.com \n"; | |
os.remove("./"+file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment