国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

使用python-pexpect登錄linux系統(tǒng)并發(fā)送命令

lijy91 / 1717人閱讀

#!/usr/bin/python
# -*- coding: utf-8 -*-
# filename: pexpect_test.py

import pexpect,time,sys
def sendCommt():
    demo = open("result.txt", "ab")
    demo.write("==========Log Tile: demo==========
")
    print user
    child = pexpect.spawn("ssh %s@%s" % (user,ip))
    while True:
        i = child.expect(patterns)
        if i == CONTINUES:
            child.sendline(flag)
        elif i == PASSWD:
            child.sendline(passwd)
        elif i == OPFLAG:
            break
    for cmd in cmds:
        time.sleep(2)
        p = pexpect.spawn(cmd)
        p.logfile = demo
        p.write("=====================
")
        p.expect(pexpect.EOF)
        print cmd
    demo.close()
    child.close()

if __name__ == "__main__":
    user = "demo"
    ip = "x.x.x.x"
    passwd = "1"
    cmds = ["ps","ls","pwd","ifconfig","date"]
    patterns = ["Are you sure you want to continue connecting (yes/no)?","[Pp]assword:","#"]
    CONTINUES,PASSWD,OPFLAG = range(len(patterns))
    flag = "yes"
    group = "1"
    try:
        sendCommt()
    except pexpect.TIMEOUT:  
        print "TIMEOUT" 
    except pexpect.EOF:
        print "EOF"

參考文檔:
http://www.ibm.com/developerworks/cn/lin...

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/37855.html

相關文章

  • linux文件系統(tǒng)和日志分析

    摘要:通常情況下不需要關注單個的大小,而是需要重點關注的總數(shù),的總字節(jié)在格式化的時候就給定了,執(zhí)行命令即可查看每個硬盤分區(qū)對應的總數(shù)和已經(jīng)使用的數(shù)量。 inode和block概述一:1、文件數(shù)據(jù)包括源信息與實際數(shù)據(jù)文件存儲在硬盤上,硬盤最小存儲單位是扇區(qū)。每個扇區(qū)存儲512字節(jié)block (塊):連續(xù)的八個扇區(qū)組成一...

    waruqi 評論0 收藏0

發(fā)表評論

0條評論

lijy91

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<