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 is in syncfail, if it is syncfail, login into CIPS to get login.
"""
import paramiko
import ssh
import os
import re
import time
import appdirs
import packaging
import packaging.version
import packaging.specifiers
import packaging.requirements
import pyasn1.type
import pyasn1.type.univ
paramiko.__version__
appdirs.__version__
packaging.__version__
packaging.version.__doc__
packaging.specifiers.__doc__
packaging.requirements.__doc__
pyasn1.type.__doc__
pyasn1.type.univ.__doc__
#定义syncfail异常类
class Syncfail_Exception(Exception):
def __init__(self,value):
self.value=value
def __str__(self):
return self.value
#定义
class syncfail(object):
def __init__(slef,neip,cipsip,ss=5):
slef.neip = neip
slef.cipsip = cipsip
slef.ss=ss
def __str__(slef):
print "Syncfail or not, is a question!"
def checksyncfail(self):
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(self.neip,port,username,password)
ssh=s.invoke_shell()
self.ss-=2
while(1):
time.sleep(self.ss)
ssh=s.invoke_shell()
ssh.send('cat /var/log/dpkg_cfpal.log|grep syncfail\n')
time.sleep(2)
x = ssh.recv(10000)
#print x
pattern1=re.compile(r'(into syncfail state)')
y=re.findall(pattern1,x)
#y=1 just for test
if y:
print 'Syncfail occurs:\n',x,'\n',time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
else:
print 'No syncfail here.',time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
if y:
try:
raise Syncfail_Exception('Syncfail occurs')
except Syncfail_Exception,e:
print e
self.getlog(self.neip,self.cipsip)
break
def getlog(self,neip,cipsip):
port = 22
username = 'root'
password = 'root'
s = paramiko.SSHClient()
s.load_system_host_keys()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(self.neip,port,username,password)
ssh=s.invoke_shell()
ssh.send('/etc/init.d/xinetd stop\n\
tcpsvd 0 21 ftpd -w /ftppub &\n\
/etc/init.d/xinetd start\n')
time.sleep(2)
ssh.send('scp -vr root@'+cipsip+': /var/volatile/log/ /sdlog/\n')
time.sleep(1)
x1=ssh.recv(10000)
print x1+'\n'
pattern2=re.compile(r'Are you sure you want to continue connecting')
y1=re.findall(pattern2,x1)
if y1:
ssh.send('yes\n')
time.sleep(1)
x2=ssh.recv(10000)
print x2+'\n'
print 'The log is in sdlog/log/ now.\n'
if __name__=='__main__':
neip=raw_input('Please put in your NE IP, such as 200.200.180.24:')
cipsip=raw_input('Please put in your CIPS IP:')
ss=int(raw_input('Please put in the check interval time(s>3)'))
sync=syncfail(neip,cipsip,ss)
sync.checksyncfail()
raw_input('Print any to quit!')
A python script to check NE syncfail and get log from CIPS的更多相关文章
- (copy) Shell Script to Check Linux System Health
source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...
- 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 ...
- --- no python application found, check your startup logs for errors
--- no python application found, check your startup logs for errors 碰到这个问题,请留意下系统执行的python版本和自己的djan ...
- 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 的位置也需使用 絕對路徑 如果要在 ...
- MS SQL错误:SQL Server failed with error code 0xc0000000 to spawn a thread to process a new login or connection. Check the SQL Server error log and the Windows event logs for information about possible related problems
早晨宁波那边的IT人员打电话告知数据库无法访问了.其实我在早晨也发现Ignite监控下的宁波的数据库服务器出现了异常,但是当时正在检查查看其它服务器发过来的各类邮件,还没等到我去确认具体情 ...
- python+selenium之自定义封装一个简单的Log类
python+selenium之自定义封装一个简单的Log类 一. 问题分析: 我们需要封装一个简单的日志类,主要有以下内容: 1. 生成的日志文件格式是 年月日时分秒.log 2. 生成的xxx.l ...
- NE Upgrade python script. Need to write a Tkinter GUI for it
# -*- coding: utf-8 -*-#from ftplib import FTP __authour__='CC' import osimport telnetlibimport time ...
随机推荐
- 使用CXF框架集成Spring实现SOAP Web Service
- MVC中自带的异步((Ajax.BeginForm)无效
1.确定unobtrusive-ajax已经引用,VS2012带,2013不带 2.注意jq和unobtrusive-ajax引用顺序问题,确保jq在前 3.注意JQ和unobtrusive-ajax ...
- .net 调用java rest ful api 实例
注意post的参数组合 HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = &quo ...
- python爬虫感想
老师说,能用程序解决一个实际问题,说明已经会使用工具了.今天用python做了一个小爬虫,很幸运,成功了. 有几个难点:就是学会伪装,还有一个觉得打开的方式太多,有点糊涂,正则表达式也要加强了.
- mySql 注入攻击
注入攻击 1.原理: a.只要是带有参数的动态网页且此网页访问了数据库,那么就有可能存在SQL注入; b.字符串拼接和没有判断用户输入是否合法------>导致用户可以玩填字游戏-----> ...
- hashmap的底层实现
HashMap的底层实现都是数组+链表结构实现的,添加.删除.获取元素都是先计算hash值,根据hash值和table.length计算出index也就是table的数组的下标,然后进行相应的操作. ...
- JAVA序列化和反序列化
http://developer.51cto.com/art/201202/317181.htm http://blog.csdn.net/earbao/article/details/4691440 ...
- PowerShell 连接SQL
因为对SQL操作比较多,但有些操作其实都是重复性的,只是参数不太一样了,例如silo id, server name 等.希望可以通过powershell脚本提高效率. 尝试如下 1. 使用Power ...
- centos 配置 ssl服务
使用的是appach 2.4.10 版本 各个版本配置不同 1.首先修改httpd.conf 文件 appach 安装目录下的 conf文件夹中找到 #LoadModule socache_shmcb ...
- Connect to Database Using Custom params链接数据库配置参数说明
使用RF的关键字Connect to Database Using Custom params链接数据库,对应的参数说明: a) 第一个参数我使用的是cx_Oracle,就写这个 b) ...