#! /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的更多相关文章

  1. (copy) Shell Script to Check Linux System Health

    source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...

  2. 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 ...

  3. --- no python application found, check your startup logs for errors

    --- no python application found, check your startup logs for errors 碰到这个问题,请留意下系统执行的python版本和自己的djan ...

  4. Windows 配置Apache以便在浏览器中运行Python script的CGI模式

    打开httpd.conf,找到”#ScriptInterpreterSource Registry “,移除前面的注释# (如果找不到这行,就自己添加进去) 找到“Options Indexes Fo ...

  5. Notepad++插件Emmet和Python Script的安装

    最近在做一个项目,涉及到大量的HTML.CSS代码的编写,手动写代码效率实在 是低下.于是想搜索一下,有没有Notepad++插件可以支持自动生成的,果不其然还真有.Emmet,这款神器其实就是 Ze ...

  6. rc.local 注意事項,call python script, file position

    如果要在 rc.local 呼叫 python script python script 的位置需使用絕對路徑 其 python script 裡的有關 file 的位置也需使用 絕對路徑 如果要在 ...

  7. 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监控下的宁波的数据库服务器出现了异常,但是当时正在检查查看其它服务器发过来的各类邮件,还没等到我去确认具体情 ...

  8. python+selenium之自定义封装一个简单的Log类

    python+selenium之自定义封装一个简单的Log类 一. 问题分析: 我们需要封装一个简单的日志类,主要有以下内容: 1. 生成的日志文件格式是 年月日时分秒.log 2. 生成的xxx.l ...

  9. 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 ...

随机推荐

  1. 如何把Excel中的某列数值如何转换成文本格式,且兼容性最好?

    假设要把下方A列数值变成文本格式.有多种方法,其中下方的方法兼容性最好: 第一步:选择 A 列,然后,运行菜单 数据/分列... 命令,如下图: 第二步:默认 下一步: 第三步:默认 下一步: 第四步 ...

  2. mysql dba系统学习(6)二进制日志binlog之二

    MySQL 5.5 中对于二进制日志 (binlog) 有 3 种不同的格式可选:Mixed,Statement,Row,默认格式是 Statement.总结一下这三种格式日志的优缺点.MySQL R ...

  3. 鸟哥linux私房菜基础篇

    1)注销:exit2)指令太长:命令太长的时候,可以使用反斜杠 (\) 来跳脱[Enter]符号,使挃令连续到下一行3)系统语言显示和设置命令:echo $LANG,显示当前系统语言:简体中文zh_C ...

  4. Android tween 动画 XML 梳理

    前言: Tween动画是展现出旋转.渐变.移动.缩放的这么一种转换过程,即补间动画.Tween动画有两种定义方式:XML形式,编码形式.这次主要来梳理XML的方式配置动画 (1)XML定义动画,按照动 ...

  5. Java里List取并集方法retainAll不能用来判断是否有重复数据!

    网上找的源码 public boolean retainAll(Collection<?> c){     boolean modified = false;     Iterator&l ...

  6. 验证控件,解决用于ajax提交前的验证,不是submit提交的验证

    //解决ajax提交前的验证问题,主要用于onclick事件时对某一区域中(可以是form,div,table中的等)控件的验证.(function ($) { var v; //Create a n ...

  7. mvc 中的 [ChildActionOnly] 和 [NonAction]

    首先,NonAction表示它不是一个真正的Action,而是一个普通方法, 就像我们定义一个普通的方法那样,返回值可以任意定义; 而  ChildActionOnly表示它只能在View中通过Htm ...

  8. HTML5 input placeholder 颜色修改

    在开发中遇到的一个小问题,记录下来./*placehodel*/ input:-ms-input-placeholder{color:#a9a9a9;}/* Internet Explorer 10+ ...

  9. 安卓版App开发心得

    从2016年4月到6月主要做的工作是网站的开发,而6月到现在2016年8月初,主要做的工作是Android和IOS两种App的开发,又以Android为主. 将这段时间的Android开发心得记录如下 ...

  10. BeanDefinitionStoreException

    异常摘要 org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML documen ...