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 ...
随机推荐
- iOS 9后修改状态栏方法
1.plist文件中添加View controller-based status bar appearance字段 值为NO 2.程序中添加 [UIApplication sharedApplicat ...
- Linux环境安装MySQL数据库
1. 下载mysql安装包 下载地址1: http://www.mysql.com/ (mysql官网) 下载地址2: http://mirrors.sohu.com/mysql/ (其 ...
- Nginx location 匹配顺序整理
Nginx location模块整理 具体的Nginx安装就不在这里描述了,这里只是为了对location的描述 Nginx环境 a. 查看当前系统cat /etc/redhat-release [r ...
- ZOJ 2412 Farm Irrigation
Farm Irrigation Time Limit: 2 Seconds Memory Limit: 65536 KB Benny has a spacious farm land to ...
- windows 下编辑shell,到linux报错,也是windows换行等造成
sed -i 's/\r$//' shell.sh 然后linux 下就不会报语法错误了.
- C语言回顾-字符串指针
1.字符串指针 char *变量名="字符串内容"; char ch='b'; char *p1=&ch; char *str="C Language" ...
- .NET开发者必备的工具箱
本文作者Spencer是一名专注于ASP.NET和C#的程序员,他列举了平时工作.在家所使用的大部分开发工具,其中大部分工具都是集中于开发,当然也有一些其它用途的,比如图片处理.文件压缩等. 如果你是 ...
- 通过cygwin安装openSSH
openSSH的安装是学习hadoop必不可少的一步,如果ssh装不好,hadoop的安装会进行不下去.本人初学hadoop时发现以前安装ssh走了一些弯路,现在又有了一些认识,所以重写了这篇日志,供 ...
- Asp.net mvc 添加Jquery UI
1.使用NuGet下载jquery ui Install-Package jQuery.UI.Combined 2.下载多语言文件: development-bundle/i18n目录下是jquery ...
- c# winform 调用js
1. 在winform中加入一个 WebBrowser 控件: 2. webBrowser控件加载html文件,html文件中包含了js代码, 代码如下(必须在 InitializeComponent ...