Mail server logs in linux
Last Update:2014-05-15
Source: Internet
Author: User
Linux mail sending server log LINUX mail server pythonsendsyslogpy send mail calling program! Usrbinenvpython-*-coding: UTF-8-*-importosimpsyssyspathappend (osgetcwd () importsendlog linux mail sending server log LINUX mail server pythonsendsyslog. py // send mail invocation program #! /Usr/bin/env python #-*-coding: UTF-8-*-import osimport syssys. path. append (OS. getcwd () import sendlog ############ sendlog. py // send mail configuration program #! /Usr/bin/env python #-*-coding: UTF-8-*-''' Created on 2012-7-25 @ author: devops@qq.com ........... log ............. fcntl ....... linux .................. pyc ..,...... py ......... 1... pyc .. python-c "import py_compile; py_compile.compile (r'/root/zyy/scripts/sendlog. py ') "2 ..... py .. sendsyslog. py #! /Usr/bin/env python #-*-coding: UTF-8-*-import osimport syssys. path. append (OS. getcwd () import sendlog ''' from email. header import Headerfrom email. MIMEText import MIMETextfrom email. MIMEMultipart import MIMEMultipartimport smtplibimport datetimeimport socket import fcntlimport struct def get_ip_address (ifname): s = socket. socket (socket. AF_INET, socket. SOCK_DGRAM) return socket. inet_ntoa (fcntl. ioctl (s. fileno (), 0x8915, # SIOCGIFADDR struct. pack ('256s ', ifname [: 15]) [20:24]) host = "host" + get_ip_address ('eth0 '). split (". ") [3] mail_user =" sender "mail_pass =" sender's email password "mail_sender =" sender's email "mail_recipients = [" recipient's email address 1 ", "recipient email address 2"] mail_server = "email server" logpath = "Send attachment storage directory" logname = str (datetime. date. today () + ". log "logfile = logpath + logname #.......... msg = MIMEMultipart ()#.... att = MIMEText (open (logfile, 'RB '). read (), 'base64', 'utf-8 ') att ["Content-Type"] = 'application/octet-stream' att ["Content-Disposition"] = 'attachment; filename = % s % s' % (host, logname) msg. attach (att )#.... msg ['from'] = mail_sendermsg ['subobject'] = Header ('server % s daily log ('% host + str (datetime. date. today () + ')', 'utf-8 ')#.... server = smtplib. SMTP () server. connect (mail_server) server. login (mail_user, mail_pass) server. sendmail (mail_sender, mail_recipients, msg. as_string () server. close ()""