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 ...
随机推荐
- 如何使用Profiler跟踪阻塞信息
Blocked Process ReportProfiler提供一个被阻塞进程报告的事件Errors and Warnings->Blocked Process Report 指示某个任务已被阻 ...
- 4. Java Script 变量(untype)
没有块级作用域 数据类型 JavaScript中有5种简单数据类型(也称为基本数据类型):Undefined.Null.Boolean.Number和String.还有1种复杂数据类型——Object ...
- asp.net mvc 5 web api 关于Requested resource does not support options 问题
1.用visual studio 2015 建立一个 web api 应用程序.记住这是一个 web api 应用. 2.新建一个web api . 3.用C#访问,代码如下:[没有问题,返回正确] ...
- ferret不能创建txt文本
设置文件夹权限为可读写也没用~郁闷中.
- 2-MySQL数据库编码uft-8
mysql> show variables like 'character%'; mysql> show variables like 'collation%'; mysql> st ...
- Windows Phone 六、JSON序列化
JSON序列化 public class Person { public int Id { get; set; } public string Name { get; set; } public in ...
- SASS 初学者入门
SASS 初学者入门 Sass 是什么? Sass 是Syntactically Awesome Stylesheete Sass的缩写,是由Hampton Catlin开发的. Sass可以简化你的 ...
- javaSE第三篇
1.classpath: set classpath = 类路径 用来找class文件 set classpath = .;(默认表示当前路径 2.数组的拷贝 方法一:Arrays.copyOf( ...
- TCL笔试题 将A,B,B,C,D,E,第三个字符不可以是E的所有组合输出;
思路:利用排列思想,进行递归:#include "iostream" using namespace std; ]; void pick_one(char a[],int num[ ...
- Python Thread related
1.Thread.join([timeout]) Wait until the thread terminates. This blocks the calling thread until the ...