Mail server logs in linux

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 ()""
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.