20.23 Alarm system Mail engine (UP)
mail.sh Content
which mail.py content to download here https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D22Z/mail.py
Log=$1
t_s=date +%s
T_s2=date -d "2 hours ago" +%s
if [!-f/tmp/$log]
Then
echo $t _s2 >/tmp/$log
Fi
T_s2=tail -1 /tmp/$log|awk ‘{print $1}‘
echo $t _s>>/tmp/$log
v=$[$t _s-$t _s2]
Echo $v
If [$v-GT 3600]
Then
./mail.py $ $
echo "0" >/tmp/$log. txt
Else
if [!-f/tmp/$log. txt]
Then
echo "0" >/tmp/$log. txt
Fi
nu=cat /tmp/$log.txt
nu2=$[$nu +1]
echo $nu 2>/tmp/$log. txt
If [$nu 2-GT 10]
Then
./mail.py $ "Trouble continue ten Min" "$ $"
echo "0" >/tmp/$log. txt
Fi
Fi??
Operation Process
[Email protected] mon]# cp/usr/lib/zabbix/alertscripts/mail.py mail/mail.py
[email protected] mon]# cat mail/mail.py
#!/usr/bin/env python
#--Coding:utf-8--
Import Os,sys
Reload (SYS)
Sys.setdefaultencoding (' UTF8 ')
Import getopt
Import Smtplib
From email. Mimetext Import Mimetext
From email. Mimemultipart Import Mimemultipart
From subprocess Import *
def sendqqmail (username,password,mailfrom,mailto,subject,content):
Gserver = ' smtp.163.com '
Gport = 25
Try
msg = Mimetext (Unicode (content). Encode (' Utf-8 '))
Msg[' from '] = Mailfrom
Msg[' to '] = mailto
msg[' reply-to '] = Mailfrom
msg[' Subject '] = Subject
SMTP = Smtplib. SMTP (Gserver, Gport)
Smtp.set_debuglevel (0)
Smtp.ehlo ()
Smtp.login (Username,password)
Smtp.sendmail (Mailfrom, mailto, msg.as_string ())
Smtp.close ()
Except Exception,err:
Print "Send Mail failed. Error:%s "% err
def main (): Br/>to=sys.argv[1]
SUBJECT=SYS.ARGV[2]
CONTENT=SYS.ARGV[3]
# #定义QQ邮箱的账号和密码, you need to change your own account and password (please do not put the real user name and password on the Internet, otherwise you will die badly)
Sendqqmail ('[email protected]', ' aaaaa ', '[email protected]', to,subject,content)
Name== "Main":
Main ()
# # # # #脚本使用说明 ######
#1. First, define the email account and password in the script.
#2. Script execution commands are: Python mail.py target Mailbox "message subject" "Message content"
[email protected] mon]# vim mail/mail.sh
Write the above mail.sh content
20.26 Operating Alarm System
2018-06-05 Linux Learning