这个是进程nginx的,大家可以修改下里面的 ps -C 进程名
#!/usr/bin/env python
import os, sys, time
while True:
time.sleep(3)
try:
ret = os.popen('ps -C nginx -o pid,cmd').readlines()
if len(ret) <2:
print "nginx process killed, restarting service in 3 seconds."
time.sleep(3)
os.system("service nginx restart")
except:
print "Error", sys.exc_info()[1]
邮件的可以用话smtplib发送
#!/usr/bin/python
# -*- coding: utf-8 -*-
import smtplib
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
def send_mail(to, sub, content, from_email, mail_pass, filelist = []):
'''
to:发给谁
sub:主题
content:内容
from_email:登录邮箱
mail_pass:登录密码
filelist:附件列表,文件路径
send_mail("[email protected]","the5fire","welcome to the5fire.net","[email protected]","xxxxxx")
'''
mail_postfix = from_email.split('@')[1]
mail_host="smtp.%s" % (mail_postfix,)
mail_user= from_email.split('@')[0]
me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = sub.encode('gbk')
msgRoot['Form'] = me
msgRoot['To'] = to
msgRoot.preamble = 'this is a multi-part message IN MIME format'
msgAlternative = MIMEMultipart('alternative')
msgRoot.attach(msgAlternative)
msgText = MIMEText(content, 'html','gbk')
msgAlternative.attach(msgText)
for onefile in filelist:
att = MIMEText(open(onefile,'rb').read(),'base64','gb2312')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment;filename=%s' % onefile
msgAlternative.attach(att)
message = msgRoot.as_string()
try:
s = smtplib.SMTP()
try:
s.connect(mail_host)
except Exception,e:
print str(e)
s.starttls()
s.login(mail_user,mail_pass)
s.sendmail(me, to, message)
s.close()
return True
except Exception, e:
print str(e)
return False