0

I am trying to ssh to a Linux server using the below script. The script did not give any error but it doesn't give any result of COMMAND as well.

import subprocess
import sys


HOST = "IP ADDRESS"
COMMAND = "ifconfig"


def passwordless_ssh(HOST):
    ssh = subprocess.Popen(
        ["ssh", "%s" % HOST, COMMAND],
        shell=False,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    result = ssh.stdout.readlines()
    if result == []:
        error = ssh.stderr.readlines()
        print >> sys.stderr, "ERROR: %s" % error
        return "error"
    else:
        return result
theherk
  • 6,954
  • 3
  • 27
  • 52

0 Answers0