|
#!/usr/bin/python
#coding:utf8
#file topid.py
import smtplib,mimetypes #mail module
import time #system time
import sys,os
from email.mime.text import MIMEText #mail type mode
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
#sys and date messages
datetime = time.strftime('%Y-%m-%d %H:%M:%S') #get time
dataname = "tlcytop"
#mail messages
msg = MIMEMultipart()
msg['From'] = "test@163.com"
msg['To'] = "test@163.com"
msg['Subject'] = "dataname %s time %s" %(dataname,datetime)
smtp = smtplib.SMTP()
smtp.connect("smtp.audiocn.com")
smtp.login("test@163.com",'password')
a=sys.argv[1] #传递参数
a=int(a) #数据类型转换
if (a < 450):
#ddprint "ok %s" % (a)
txt = MIMEText("Subject: %s tlcytop.edit_ugc-------->updatetime<450 updatetime= %s" % (datetime,a ))
msg.attach(txt)
smtp.sendmail('test@163.com', 'test1@163.com',msg.as_string())
smtp.sendmail('test@163.com', 'test2@163.com',msg.as_string()) #发送邮件
smtp.quit()
调用python的shell脚本
#/bin/bash
#
#a=`/usr/bin/mysql -uroot -p123456 -e "select count(user) from mysql.user;" |sed -n '2p'`
a=`/usr/bin/mysql -uxxx -hxxx -pxxxx -e "select COUNT(*) from tlcytop.edit_ugc where updatetime > '2016-01-07 00:00:00'" |sed -n '2p'`
source ~/.bashrc && /usr/bin/python /home/tiantao/mysqldcheck.py $a
|
|