以下内容在一个文件中。我使用 shell 脚本调用 python 脚本。这个 python 脚本发送邮件。但是在邮件内容中我看到输出如下所示。它都在一个行中。我做错了什么
/usr/bin/python $DIR/sm.py "$message" "`cat /tmp/alert.txt`"
输入:以下是alert.txt的内容
Thu Jun 28 14:29:26 IST 2012
Disk usage limit exceeded -Current disk usage is 167G-Configured disk usage is 200HTTPD connections exceeded configured usage limit -Current HTTPD connections is 21-Configured HTTPD connection is 20
========================OTHER INFO==================
Total fds: 8
Socket fds: 0
Other fds: 8
Free memory :Free Memory:183732
Buffered memory Buffered Memory:78224
Cache memory : Cache Memory:579040
Disk usage is 167G
DB connections 1
Network connections 21
CPU Usage: 0.0
输出:
Thu Jun 28 14:29:26 IST 2012 Disk usage limit exceeded -Current disk usage is 167G-Configured disk usage is 200HTTPD connections exceeded configured usage limit -Current HTTPD connections is 21-Configured HTTPD connection is 20 ========================OTHER INFO================== Total fds: 8 Socket fds: 0 Other fds: 8 Free memory :Free Memory:183732 Buffered memory Buffered Memory:78224 Cache memory : Cache Memory:579040 Disk usage is 167G DB connections 1 Network connections 21 CPU Usage: 0.0
这是 sm.py
import logging
import smtplib
import sys
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
try:
smaid = qs[0].id
gmailUser = 'no-reply@xxxxxxxxxxx.com'
gmailPassword = '12345'
mailServer = smtplib.SMTP('smtp.gmail.com', 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmailUser, gmailPassword)
to_addr = "xxxxx@xx.com"
subject = sys.argv[1]
body = sys.argv[2]
try:
msg = MIMEMultipart()
msg['From'] = gmailUser
msg['To'] = to_addr
msg["Content-type"] = "text/html"
sub = subject
msg['Subject'] = sub
body = body
msg.attach(MIMEText(body, 'html'))
mailServer.sendmail(gmailUser, to_addr, msg.as_string())
except:
write_exception("send exception")
mailServer.close()
except:
write_exception("send exception1")