import pexpect
ssh = pexpect.spawn('ssh localhost') #建立新线程,执行"通过ssh连接本地"
ssh.expect('.*password:') #正则匹配输入密码提示,匹配才继续执行
ssh.sendline("123456") #输入密码
ssh.interact() #执行
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
from pexpect import * | |
log = file('mylog.txt','w') | |
c = spawn('/bin/bash') | |
c.expect_exact('$') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
#Notice:Please close domain lookup on your router or switch. | |
__author__="ring0" | |
__date__ ="$2011-6-5 16:00:00$" | |
__version__ ="0.3" | |
import sys | |
try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pxssh | |
def send_command(s, cmd): | |
s.sendline(cmd) | |
s.prompt() | |
print s.before | |
def connect(user, host, password): | |
try: | |
s = pxssh.pxssh() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'pty' | |
require 'expect' | |
require 'timeout' | |
# expect で読み込んだ内容を標準出力に出力するおまじない | |
$expect_verbose=true | |
class MkdirExpect |