Re: ssh
- From: gert <gert.cuykens@xxxxxxxxx>
- Date: Wed, 30 Apr 2008 04:04:45 -0700 (PDT)
Eric Wertman wrote:
from popen2 import Popen3
def ssh(host,command) :
''' Wraps ssh commands '''
ssh_exec = ['/usr/bin/ssh -qnx -F ssh_config', host, command]
cmd = ' '.join(ssh_exec)
output,errors,status = process(cmd)
return output,errors,status
def process(cmd) :
proc = Popen3(cmd,-1)
output = proc.fromchild.readlines()
errors = proc.childerr.readlines()
status = proc.poll()
return output,errors,status
thanks, what happens with the ssh connection after def process(cmd) is
done
Do i not need to remove the 'else' for it to work ?
Also can i execute multiple commands at once ?
import os, time
def ssh(user, rhost, pw, cmd):
pid, fd = os.forkpty()
if pid == 0:
os.execv("/bin/ssh", ["/bin/ssh", "-l", user, rhost] +
cmd)
time.sleep(0.2)
os.read(fd, 1000)
time.sleep(0.2)
os.write(fd, pw + "\n")
time.sleep(0.2)
res = ''
s = os.read(fd, 1)
while s:
res += s
s = os.read(fd, 1)
return res
print ssh('username', 'serverdomain.com', 'Password', ['ls -l'])
.
- Prev by Date: Re: computing with characters
- Next by Date: Re: best way to host a membership site
- Previous by thread: Re: ssh
- Next by thread: xml.dom.minidom weirdness: bug?
- Index(es):
Relevant Pages
|