获取 Linux 磁盘使用情况并发送警报邮件

mailto_list=["xx", "xxx"]
use01=commands.getstatusoutput("df -lh | sed -n '/\/$/p' | awk '{print $5}' | awk -F '%' '{print $1}'")

free01=use01[1]
print free01
used_disk=int(free01)

def send_email(alert_content):
    sender = ''
    receiver = mailto_list
    subject = ""
    smtpserver = ''
    username = ''
    password = ''

    msg = MIMEText(alert_content,'html','utf-8')

    msg['Subject'] = subject

    smtp = smtplib.SMTP()
    smtp.connect(smtpserver)
    smtp.login(username, password)
    smtp.sendmail(sender, receiver, msg.as_string())
    smtp.quit()


if __name__ == '__main__':
    content = ''
    if used_disk > 80:
        content += "%s%s"%(used_disk, '%')
    if (content != ""):
        send_email(content)