#!/usr/bin/env python
#!coding=utf-8
import os
import time
import sys
import smtplib
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart def sendsimplemail (warning):
msg = MIMEText(warning)
msg['Subject'] = 'python first mail'
msg['From'] = 'root@localhost'
try:
smtp = smtplib.SMTP()
smtp.connect(r'pop.qq.com')
smtp.login('1427746783@qq.com', 'passwd')
smtp.sendmail('1427746783@qq.com', ['1427746783@qq.com'], msg.as_string())
smtp.close()
except Exception, e:
print e time_str = time.strftime( "%Y-%m-%d", time.localtime( ) )
file_name = "./" + time_str + ".log" while True:
print_str = "";
Pro_status = os.popen('netstat -tulnp | grep nginx','r').readlines()
now_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
try:
if Pro_status == []:
os.system('service nginx start')
new_Pro_status = os.popen('netstat -tulnp | grep nginx','r').readlines()
str1 = ''.join(new_Pro_status)
port = str1.split()[3].split(':')[-1]
if port != '9999':
print_str = print_str + "nginx start fail ..."
else:
print_str = print_str + "nginx Program abort. an internal error has occurred" + '\n'
print_str = print_str + "nginx start success ..."
# sendsimplemail(warning = "This is a warning!!!")
else:
print_str = print_str + now_time +"nginx running ..."
time.sleep(3) if os.path.exists ( file_name ) == False :
os.mknod( file_name )
handle = open ( file_name , "w" )
# print ( print_str + "**********1")
try:
handle.write( print_str)
except:
log.error('write backup error:')
finally:
handle.close()
# print ( print_str + "**********2")
else:
handle = open ( file_name , "a" )
print ( print_str + "**********3")
handle.write( print_str + '\n') except KeyboardInterrupt:
sys.exit('\n')

这个是jkport更新版, 旧版在这里:python监控端口脚本

新增日志输出功能

运行模式, 直接守护:nohup ./jkport.py &

不用像以前那么繁琐。

python监控端口脚本[jkport2.0.py]的更多相关文章

  1. python监控端口脚本[jkport1.0.py]

    此脚本根据端口判断进程是否存活, 如果有指定的端口就证明进程是没问题的, 如果检测不到端口就是说业务进程已经挂掉了, 此时自动重启程序, 不多说下面请看脚本 创建脚本 我这里模拟的是nginx, 监控 ...

  2. python扫描端口脚本

    # -*- coding:utf8 -*- # # Python: 2.7.8 # Platform: Windows # Authro: wucl # Program: 端口扫描 # History ...

  3. Python 监控脚本

    Python 监控脚本 整体通过psutil模块动态获取资源信息.下为示例图: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time: 2019- ...

  4. centos 7中监控mysql 数据库脚本(监控端口)

    centos 7中监控mysql 数据库脚本(监控端口) 监控mysql数据库的方法如下: 1.监控端口 netstat -nltp |grep 3306 2.监控进程 ps -ef |grep 33 ...

  5. 【JMeter4.0学习(五)】JMeter对服务器监控测试脚本开发

    目录: 下载相关JMeter插件 服务器监控测试脚本开发 附:参考相关文档 本文主要来说一下如何通过JMeter插件来监控服务器CPU.内存.磁盘.网络等相关资源. 一.首先,需要下载相关JMeter ...

  6. python 监控redis的进程与端口

    #!/usr/bin/python # -*- coding:utf-8 -*- import glob,psutil import json,os,datetime import collectio ...

  7. 【Linux】CentOS下升级Python和Pip版本全自动化py脚本

    [Linux]CentOS下升级Python和Pip版本全自动化py脚本 CentOS7.6自带py2.7和py3.6 想要安装其它版本的话就要自己重新下载和编译py其它版本并且配置环境,主要是软链接 ...

  8. Zabbix如何实现批量监控端口状态

    引言 ------------------------------------------------------------------------------------------------- ...

  9. Python数据库备份脚本

    Python数据库备份脚本 #!/usr/bin/env python # author: liudong # -*- coding: utf-8 -*- # filename: db_bak.py ...

随机推荐

  1. 【紫书】Oil Deposits UVA - 572 dfs求联通块

    题意:给你一个地图,求联通块的数量. 题解: for(所有还未标记的‘@’点) 边dfs边在vis数组标记id,直到不能继续dfs. 输出id及可: ac代码: #define _CRT_SECURE ...

  2. DS作业·写了一个链表

    用struct手写了个list 有push_back,push_front,insert,erase reserve,size,setpos,rbegin 功能. 坑:一开始想用template< ...

  3. ResourceManager High Availability

    Introduction This guide provides an overview of High Availability of YARN’s ResourceManager, and det ...

  4. linux:echo命令示例

    echo命令:用于字符串的输出  $echo string 1.打印普通字符串 $echo "hello kumata" hello kumata #这里的双引号完全可以省略,以下 ...

  5. 在浏览器地址栏输入一个URL后回车,将会发生的事情?

    https://yq.aliyun.com/articles/20667

  6. msc文件

    MSC微软管理控制台(Microsoft Management Control)文件.可以点击开始/运行,然后输入下列文件名就可以打开相应的控制窗口. 除第三个文件外,其他均在C:\WINDOWS\s ...

  7. JAVA 的wait(), notify()与synchronized同步机制

    转自:http://blog.csdn.net/zyplus/article/details/6672775 在JAVA中,是没有类似于PV操作.进程互斥等相关的方法的.JAVA的进程同步是通过syn ...

  8. WebWorker的浏览器"异步线程"

    worker新线程: 1.通过postMessage( data ) 方法来向主线程发送数据; 2.绑定onmessage方法来接收主线程发送过来的数据:   3.worker外部文件不允许使用win ...

  9. Jungle Roads---poj1251 hdu1301

    Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid ...

  10. 腾讯在线文档发布:实现QQ、微信多平台多人协作编辑

    18日,腾讯宣布推出专注多人协作的在线文档产品—腾讯文档,据介绍,腾讯文档是一款支持随时随地创建.编辑的多人协作式在线文档工具,拥有一键翻译.实时股票函数和浏览权限安全可控等功能,以及打通QQ.微信等 ...