#!/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. 1.0Tensorflow中出现编译问题的解决方案

    跑简单tf例程的时候遇到这个 sess = tf.Session(),I tensorflow/core/platform/cpu_feature_guard.cc:] Your CPU suppor ...

  2. uoj#228. 基础数据结构练习题(线段树区间开方)

    题目链接:http://uoj.ac/problem/228 代码:(先开个坑在这个地方) #include<bits/stdc++.h> using namespace std; ; l ...

  3. 改革春风吹满地---hdu2036(多边形用差积求面积)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2036 #include<iostream> #include<stdio.h> ...

  4. Servlet----------用servlet写一个“网站访问量统计“的小案例

    package cn.example; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Ser ...

  5. Redis具体解释与常见问题解决方式

    Redis简单介绍 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对很多其它.包含string(字符串).list(链表).set(集合).zset ...

  6. VMware上安装VMware tools

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/walkerkalr/article/details/34896407  VMware上安装VMw ...

  7. requesMapping注解

    java类 package org.springframework.web.bind.annotation; import java.lang.annotation.Documented; impor ...

  8. [js]js中原型的继承

    js继承01 思路: 单例/工厂/构造函数--演进到原型 搞清原型结构 原型继承 模拟系统原型继承 实现自己的继承 观察原型继承特点 演进到原型链这一步 //单例模式: 防止变量名冲突: // 思路: ...

  9. [django]JsonResponse序列化数据

    def home(request): data = { 'name': 'maotai', 'age': 22 } import json return HttpResponse(json.dumps ...

  10. 顺序结构,判断结构 if,switch

    1:顺序结构:从上往下执行程序代码,为顺序结构 ---------------------------------------------------------------------- 2:判断结 ...