#!/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
摘要:通常情況下不需要關注單個的大小,而是需要重點關注的總數(shù),的總字節(jié)在格式化的時候就給定了,執(zhí)行命令即可查看每個硬盤分區(qū)對應的總數(shù)和已經(jīng)使用的數(shù)量。 inode和block概述一:1、文件數(shù)據(jù)包括源信息與實際數(shù)據(jù)文件存儲在硬盤上,硬盤最小存儲單位是扇區(qū)。每個扇區(qū)存儲512字節(jié)block (塊):連續(xù)的八個扇區(qū)組成一...
閱讀 3110·2021-11-10 11:36
閱讀 3312·2021-10-13 09:40
閱讀 6051·2021-09-26 09:46
閱讀 662·2019-08-30 15:55
閱讀 1409·2019-08-30 15:53
閱讀 1580·2019-08-29 13:55
閱讀 2997·2019-08-29 12:46
閱讀 3204·2019-08-29 12:34