I write it yesterday to watch the NE process(rcpfd,cfgd) automatically, then i will write a window to implement it:

#! /usr/bin/env python
# -*- coding: UTF-8 -*-

import paramiko
import ssh
import os
import re
import time
#RCPD异常类
class RCPD_Exception(Exception):
def __init__(self,value):
self.value=value
def __str__(self):
return self.value

#CFGD异常类
class CFGD_Exception(Exception):
def __init__(self,value):
self.value=value
def __str__(self):
return self.value

#check进程的函数,进程stuck会报异常,每ss(s>1)秒check一次
def check(hostname,ss):
hostname=hostname
port = 22
username = 'root'
password = 'root'
#os.chdir(r'C:\Users\cchen\Desktop')
paramiko.util.log_to_file('paramiko.log')
s = paramiko.SSHClient()
s.load_system_host_keys()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname,port,username,password)
ssh=s.invoke_shell()
ss-=1
while(1):
time.sleep(ss)
ssh=s.invoke_shell()
ssh.send('ps -ef\n')
time.sleep(1)
x = ssh.recv(10000)
#print x
pattern1=re.compile(r'(./rcpd|\[rcpd\])')
rcpd=re.findall(pattern1,x)
print rcpd,time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
pattern2=re.compile(r'(./cfgd|\[cfgd\])')
cfgd=re.findall(pattern2,x)
print cfgd,time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
if not rcpd[0]=='./rcpd':
try:
raise RCPD_Exception('RCPD stuck')
except RCPD_Exception,e:
print e

if not cfgd[0]=='./cfgd':
try:
raise CFGD_Exception('CFGD stuck')
except CFGD_Exception,e:
print e

if __name__=='__main__': check('200.200.180.18',8)

My first python script for work的更多相关文章

  1. java + spring (jython\python\script) Error:SyntaxError: no viable alternative at character '\n'

    使用Jython结合java和Python开发功能时,要是遇到如下情况: 2016-03-10 16:16:49 DEBUG [com.freedom.orion.configs.JyhtonConf ...

  2. Windows 配置Apache以便在浏览器中运行Python script的CGI模式

    打开httpd.conf,找到”#ScriptInterpreterSource Registry “,移除前面的注释# (如果找不到这行,就自己添加进去) 找到“Options Indexes Fo ...

  3. Notepad++插件Emmet和Python Script的安装

    最近在做一个项目,涉及到大量的HTML.CSS代码的编写,手动写代码效率实在 是低下.于是想搜索一下,有没有Notepad++插件可以支持自动生成的,果不其然还真有.Emmet,这款神器其实就是 Ze ...

  4. rc.local 注意事項,call python script, file position

    如果要在 rc.local 呼叫 python script python script 的位置需使用絕對路徑 其 python script 裡的有關 file 的位置也需使用 絕對路徑 如果要在 ...

  5. A python script to check NE syncfail and get log from CIPS

    #! /usr/bin/env python # -*- coding: UTF-8 -*- """The script is to check whether NE i ...

  6. [译]Why do people write #!/usr/bin/env python on the first line of a Python script?

    If you have several versions of Python installed, /usr/bin/env will ensure the interpreter used is t ...

  7. [Python] Execute a Python Script

    Python scripts can be executed by passing the script name to the python command or created as execut ...

  8. Excel vba call Python script on Mac

    How can I launch an external python process from Excel 365 VBA on OSX? It took me a while, but I fig ...

  9. Python script to create Screen from all Items/Graphs of a host

    #!/usr/bin/env python import urllib2 import json import argparse def authenticate(url, username, pas ...

随机推荐

  1. [CC]LOD技术

    ccGLWindow::paintGL() | ccGLWindow::fullRenderingPass(...) | ccGLWindow::drawBackground(context, ren ...

  2. 分析App应用市场, App应用有哪些类型

    随着移动互联网的流行,APP应用也是异常火爆,App应用市场就如破冰的泉水在我们的生活中到处渗透,对于App开发的的状况来分析,企业在寻找技术人员开发一款专业的App软件的时候,必须先了解用户的需求与 ...

  3. maven创建的Web工程,Eclipse 内 tomcat容器不识别的处理方法

    相信很多人都遇到这个问题,简单的说明下处理方式 前提是maven配置都是ok的,这里不多说了 1.创建web工程 mvn archetype:create -DgroupId=com.XXX.YYY ...

  4. BigInteger和BigDecimal大数操作

    有时候可能会碰到需要计算非常大的数,比如7777777777777777777777777*3333333333333333333333333333,这样的计算需要显然不能用之前的方式来进行.我们不能 ...

  5. YbSoftwareFactory 代码生成插件【十七】:先进的权限模型体系设计

    目前权限管理系统不少,但通用.灵活.符合现代企事业单位实际工作需要的不多.现有的权限系统绝大多数都是以模块为核心,而本权限模型将摒弃此类普遍的做法,将以组织机构为核心来进行权限系统的设计,因为这更符合 ...

  6. Intellij Idea 14 使用jetty-maven-plugin配置运行web工程

    在项目中接触,虽然比较简单,也是经验的积累,web工程使用maven管理和构建,IDEA也是新接触的开发工具,用了一段时间,感觉so nice! 1:Run->Edit Configuratio ...

  7. Qt qml treeview 树控件

    qml并没有提供树控件,只能自己写了.model仍然用ListModel对象,弄成层级的就行.delegate必须用loader动态的增加子控件,如此而已. [先看效果] [下载] http://do ...

  8. 2015/10 中外合璧再现辉煌—CCFC2015技术峰会

    笔者有幸参加了CCFC技术峰会,现在发布照片几张.大家看一下. 2015年10月14日,CCFC 2015电子数据取证技术峰会于四川成都举办,有200余名一线取证技术人员及国内外各行业专家参会.此次峰 ...

  9. MySQL乱码问题

      JSP的request 默认为ISO8859_1,所以在处理中文的时候, 要显示中文的话,必须转成GBK的,如下 String str=new String(request.getParamete ...

  10. 通过正则表达式实现简单xml文件解析

    这是我通过正则表达式实现的xml文件解析工具,有些XHTML文件中包含特殊符号,暂时还无法正常使用. 设计思路:常见的xml文件都是单根树结构,工具的目的是通过递归的方式将整个文档树装载进一个Node ...