#!/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...
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/37855.html
摘要:通常情况下不需要关注单个的大小,而是需要重点关注的总数,的总字节在格式化的时候就给定了,执行命令即可查看每个硬盘分区对应的总数和已经使用的数量。 inode和block概述一:1、文件数据包括源信息与实际数据文件存储在硬盘上,硬盘最小存储单位是扇区。每个扇区存储512字节block (块):连续的八个扇区组成一...
阅读 3082·2021-11-10 11:36
阅读 3252·2021-10-13 09:40
阅读 5902·2021-09-26 09:46
阅读 649·2019-08-30 15:55
阅读 1397·2019-08-30 15:53
阅读 1563·2019-08-29 13:55
阅读 2978·2019-08-29 12:46
阅读 3185·2019-08-29 12:34