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)