Guest User

Untitled

a guest
Oct 13th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import smtplib
  2. from email.MIMEMultipart import MIMEMultipart
  3. from email.MIMEBase import MIMEBase
  4. from email.MIMEText import MIMEText
  5. from email import Encoders
  6. import os
  7. import socket
  8. import time
  9.  
  10. gmail_user = "sh84.ahn@gmail.com"
  11. gmail_pwd = "xxxxx"
  12.  
  13. def mail(to, subject, text, attach):
  14. msg = MIMEMultipart()
  15.  
  16. msg['From'] = gmail_user
  17. msg['To'] = to
  18. msg['Subject'] = subject
  19.  
  20. msg.attach(MIMEText(text))
  21.  
  22. part = MIMEBase('application', 'octet-stream')
  23. part.set_payload(open(attach, 'rb').read())
  24. Encoders.encode_base64(part)
  25. part.add_header('Content-Disposition',
  26. 'attachment; filename="%s"' % os.path.basename(attach))
  27. msg.attach(part)
  28.  
  29. mailServer = smtplib.SMTP("smtp.gmail.com", 587)
  30. mailServer.ehlo()
  31. mailServer.starttls()
  32. mailServer.ehlo()
  33. mailServer.login(gmail_user, gmail_pwd)
  34. mailServer.sendmail(gmail_user, to, msg.as_string())
  35. # Should be mailServer.quit(), but that crashes...
  36. mailServer.close()
  37.  
  38.  
  39. sec = 5
  40.  
  41. while 1:
  42.  
  43. time.sleep(sec);
  44. file_list = os.listdir("./");
  45.  
  46. pstack_count = 0;
  47.  
  48. pstack_list =[];
  49.  
  50. for file in file_list:
  51. count = file.count("pstack");
  52. if count >0:
  53. pstack_list.append(file);
  54.  
  55. pstack_count += count;
  56.  
  57.  
  58.  
  59. if pstack_count >0:
  60. server_name = socket.gethostname();
  61.  
  62. for file in pstack_list:
  63. mail("sh84.ahn@gmail.com",server_name + "::pstack log", file, "./"+file);
  64. print "["+file+"]"+" send to sh84.ahn@gmail.com \n";
  65. os.remove("./"+file);
Add Comment
Please, Sign In to add comment