My first python script for work
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的更多相关文章
- 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 ...
- Windows 配置Apache以便在浏览器中运行Python script的CGI模式
打开httpd.conf,找到”#ScriptInterpreterSource Registry “,移除前面的注释# (如果找不到这行,就自己添加进去) 找到“Options Indexes Fo ...
- Notepad++插件Emmet和Python Script的安装
最近在做一个项目,涉及到大量的HTML.CSS代码的编写,手动写代码效率实在 是低下.于是想搜索一下,有没有Notepad++插件可以支持自动生成的,果不其然还真有.Emmet,这款神器其实就是 Ze ...
- rc.local 注意事項,call python script, file position
如果要在 rc.local 呼叫 python script python script 的位置需使用絕對路徑 其 python script 裡的有關 file 的位置也需使用 絕對路徑 如果要在 ...
- 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 ...
- [译]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 ...
- [Python] Execute a Python Script
Python scripts can be executed by passing the script name to the python command or created as execut ...
- 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 ...
- 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 ...
随机推荐
- .NET 串口通信中断接收,包含0X1A(作为EOF)
.NET串口通信中将`0X1A`当做EOF处理,.NET接收到EOF会触发一次接收中断,此时事件形参`SerialDataReceivedEventArgs`值为枚举 `Eof`,其他为`Chars` ...
- WPF 仪表盘 刻度盘 动态 加载中 开源
1. 表盘 参数可以设置, codeproject上写的.网址在这里. 源码里有demo,很详细. 源码在这里. 2. 动态Loading 截图效果跟实际有点不一样. 自己把源码写成 资源就好用了呗 ...
- php cUrl模拟登录,cookie保存到文件中
源码如下: <?php header("Content-Type:text/html;charset=utf-8"); //模拟群友通讯录手机号登录 $curl = curl ...
- Windows7+VirtualBox+Ubuntu本地开发环境搭建
首先下载相应的VirtualBox和Ubuntu镜像文件 安装Ubuntu操作系统 一 网络设置 将虚拟机的network连接模式设置为Bridge模式,注意无线网卡要与本机的无线网卡名称一致 在wi ...
- 记一次MVC4站点在IIS上部署的诡异问题
最近朋友的公司遇到一个站点部署问题, 朋友从事服务器维护多年,说也是花了十多天仍为解决. 经多次尝试未果,仍报错如下: 我询问了相关情况,确认了该网站是VS2013开发的,版本为,NET Framew ...
- TCPL 札记
1.函数原型符合设计要求,函数定义符合认知规律,做到见名知义,最少词汇量包含最大的信息量. 2.合理运用空行提高代码的可读性.从框架上来说有: 变量定义 初始化变量 处理 输出 返回值 3.采用伪码的 ...
- 搭建git for windows服务器
文档出处 :http://blog.csdn.net/code_style/article/details/38764203 http://blog.csdn.net/aaron_luchen/art ...
- 一些CSS
/*自定义*白烟*文本/边框/背景色*/ .text-whitesmoke,a.text-whitesmoke:link,a.text-whitesmoke:visited,.button.borde ...
- java布局学习 (二)
前文中介绍了FlowLayout和BorderLayout 本文我们将会继续介绍java中的布局方式 (3)GridLayout 网格布局 这种布局会将整个容器划分成M行*N列的网格. 如下图: ...
- oracle细节
1.oracle中NVL的含义: 如果oracle第一个参数为空那么显示第二个参数的值,如果第一个参数的值不为空,则显示第一个参数本来的值. 2.Oracle中in和exists的区别: 1).sel ...