Using shell scripts to check service opening conditions
#!/bin/bash# need to install Yum install Nmap first-y# checks whether the specified port is on function checkportstatus () {Status= ' Nmap-ss127.0.0.1-P $1| grep Open | Awk'{print $}'` if["$status"!="Open" ]; Thenreturn 0; Else return 1; Fi}checkportstatus theecho $?CheckportstatusBayiecho $?
Call Python to send QQ mail messages (can prevent spam blocking)
#-*-coding:utf-8-*-#===============================================================================# import Smtplib and mimetext#=============================================================================== fromemail. Mimetext Import Mimetext fromemail. Header import Headerimport smtplib, datetime,sys#===============================================================================# who to send to 1 people here #===============================================================================mailto_list=["[email protected]"]#===============================================================================# Set the server, user name, password, and suffix of the mailbox #===============================================================================Mail_host="smtp.qq.com"Mail_user="10402852"Mail_pass="*************"Mail_postfix="qq.com"#===============================================================================# Send mail #===============================================================================def send_mail (to_list,sub,content):" "To_list: To whom sub: topic Content: Contents Send_mail ("[email protected]","Sub","content") " "me=mail_user+"<"+mail_user+"@"+mail_postfix+">"msg=mimetext (content) msg['Subject'] =Sub msg[' from'] =Me msg[' to'] =";". Join (to_list)Try: S=Smtplib. SMTP () s.connect (mail_host) s.login (Mail_user,mail_pass) S.sendmail (Me, To_list, msg.as_string ()) S.close ()returnTrue except Exception, E:print str (e)returnFalseif__name__ = ='__main__': if Send_mail (Sys.argv[1],sys.argv[2],sys.argv[3]): Print"sent successfully" Else: Print"Send failed"
Test Case:
[email protected] huanghai]# python mail.py [email protected] Yellow Sea Test title Yellow Sea test content
Sent successfully
Shell to determine if the service is running