Re: ssh




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'])
.



Relevant Pages

  • Re: A clean way to program an interface
    ... Yes - You are correct UnidenConnection is nothing more than a pyserial ... with his naming of certain methods with the same name as the command ... def makeStatusCheckCommandFunction: ... the command strings are just passed along as the argument cmd, ...
    (comp.lang.python)
  • Re: A clean way to program an interface
    ... using some form of serial communication. ... with his naming of certain methods with the same name as the command ... def makeStatusCheckCommandFunction: ... the command strings are just passed along as the argument cmd, ...
    (comp.lang.python)
  • Re: Capturing System Call Return Values?
    ... def initialize ... @cmd = cmd ... queue = Queue.new ...
    (comp.lang.ruby)
  • Cmd Module
    ... from cmd import Cmd ... def do_login: ... that function needs only one argument but two are given. ... But i know that my first code should work without any problems or is ...
    (comp.lang.python)
  • Re: [PATCH] net: add ability to clear stats via ethtool - e1000/pcnet32
    ... def ethtool(sock, name, buf): ... fcntl.ioctl, SIOCETHTOOL, ifreq) ... def ethtool_gdrvinfo: ... cmd = struct.pack ...
    (Linux-Kernel)