经常碰到一个命令
#!/usr/bin/python
# -*- encoding:utf-8 -*-
import sys
import commands
from email.mime.text import MIMEText
import smtplib
class sendMail():
def txtMail(self,content):
msg = MIMEText(content,_subtype='plain',_charset='gb2312')
msg['to'] = '18351003638@139.com'
msg['from'] = 'exec@9ishell.com'
msg['subject'] = 'exec result'
try:
server = smtplib.SMTP()
server.connect('smtp.mxhichina.com')
server.login('exec@9ishell.com','password')
server.sendmail(msg['from'], msg['to'],msg.as_string())
server.quit()
print("发送成功")
except Exception as e:
print(str(e))
if __name__=='__main__':
comm= ' '.join( [ str(x) for x in sys.argv[1:]])
(status, output) = commands.getstatusoutput(comm)
sendMail().txtMail("comm:%s;status:%s;output:%s" % (comm,status,output))