Monitor processes based on process name (MailTips)

Source: Internet
Author: User
Tags python script

Background: When monitoring UDP ports in the Windows Server system, the port changes after each process restart and attempts to discard the idea of monitoring the port instead of monitoring the process name.

Bat
:: Final interpretation is owned by Chenglee::thankyou:: Warm tip: If you put in the win start plan, if necessary to open the sixth line of code,:: The function is to detect immediately after the automatic shutdown detection script to run next time, If not turned on is the end of the detection stop waiting for manual shutdown:: function: Window overlay:: @echo off<nul 3>nul@echo off&title Checking for System, does not Switch off, thanky Ou...set num=qq.exefor/f "Tokens=1 delims=:"%%a in (' Tasklist ') do (if "%%a" = = "%num%" goto en) if not "%%a" = = "%num%" Got o en1    : Enecho. Checking for Local%num%process is opening...pauseexit  : En1echo. Checking for local%num%process isn't opening...echo.send mail for Chengleepython mail.pypauseexit

Line 8th: Set the process name

Line 9th:

' Tasklist ', which lists all the processes in which the system is running

' Tokens ', need to scan the column (I sweep the 1th column here)

Line 10th: Determine if the contents of the scan list are consistent with NUM set by my 8th line, run the following: En section

Line 12th: Determine if the contents of the scan list are consistent with the NUM set by my 8th line, run the following: EN1 segment

Line 23rd: Already found the program is gone, call the python script process email alert

mail.py
Import smtplibfrom email.mime.text import mimetextfrom email.utils import formataddrmy_sender= ' [email protected] ' My_ pass = ' Wkzbchff ' my_user= ' [email protected] ' my_context= ' Test monitor process operation ' my_title= ' information from server ' my_chengname= ' Chenglee monitor ' Def Mail ():    ret=true    try:        msg=mimetext (My_context, ' plain ', ' utf-8 ')        msg[' from ']=formataddr ([my_ Chengname,my_sender])        msg[' to ']=formataddr (["Recipient nickname", My_user])        msg[' Subject ']=my_title        server= Smtplib. Smtp_ssl ("smtp.qq.com", 465)        Server.login (My_sender, My_pass)        Server.sendmail (My_sender,[my_user,], Msg.as_string ())        server.quit ()    except Exception:        ret=false    return Retret=mail () if RET:    Print ("Mail send is ok ...") Else:    print ("Mail Send is error ...")

Complete!

Monitor processes based on process name (MailTips)

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.