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 ...
随机推荐
- PorterDuffXfermode的用法
1.下面的Xfermode子类可以改变这种行为: AvoidXfermode 指定了一个颜色和容差,强制Paint避免在它上面绘图(或者只在它上面绘图). PixelXorXfermode 当覆盖 ...
- 安装完magento后,其他电脑无法访问magento,URL自动跳转到http://localhost/magento
问题:在电脑A上安装完了magento 1.7.0.2 然后, 在电脑A上用 http://localhost/magento 访问网站,没有问题. 但在电脑B 上用 http://192.168.4 ...
- delphi之TDataset
最近遇到了很多问题,现在做一下总结. 字符串处理: 字符串相加 var S1, S2: String; begin S1 := Concat('A', 'B'); // 连接两个字符串,S1变量等于A ...
- swift language
API reference Swift UIKit Swift 菜鸟教程 Great Installed Visual Studio Code, I found I cannot open it fr ...
- 浏览器桌面通知--Notification
前言 最近项目上要用到浏览器桌面通知,之前虽然知道有这个东西,但是一直没有用过,借此机会了解下桌面通知的机制,在此分享下. 1.权限 首先需要明确的是,不是所有网页都可以发桌面通知的,不然不得烦死,那 ...
- kali 下文件操作
记得看到一片文章中说要学习linux 不要用kali.. 不感兴趣的东西,还指望我去搞个Ubuntu.... Ctrl+I 清屏 CD命令: cd 进入用户主目录: cd ~ 进入用户主目录: cd ...
- Android开源图表之树状图和饼状图的官方示例的整理
最近由于工作需要,所以就在github上搜了下关于chart的三方框架 官方地址https://github.com/PhilJay/MPAndroidChart 由于工作需要我这里整理了一份Ecli ...
- 微信 回调模式 echostr校验失败,请您检查是否正确解密并输出明文echostr
- [原创] Gradle DSL method not found: 'android()' 和 buildToolsVersion is not specified 的解决办法。
今天在用Android Studio 2.0 打开别人的较早版本生成的工程时, 提示: Gradle DSL method not found: 'android()'. 解决办法为,打开根目录下面的 ...
- iis7 64位 操作excel的一系列问题(未完待续)
查了半天发现是IIS跑在64位环境下引起的.而64位下,是木有Access数据库的驱动的(包括Excel也不行). 解决办法是:在目标网站的应用程序池中选择高级设置,然后将启用32位应用程序设置为tr ...