편집 기록

편집 기록
  • 프로필 편집요청빌런님의 편집
    날짜2020.04.24

    파이썬 paramiko sshclient 질문


    (A 스크립트)

    whereis = os.popen("which fdisk") 
    print(whereis.read())
    

    위 A 스크립트를 로컬에서 실행시키면 정상 출력이 되는데

    (B 스크립트)

    ssh = paramiko.SSHClient()
    ssh.load_system_host_keys()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(ip,username=user,password=pw)
    scp = SCPClient(ssh.get_transport())
    scp.put('/python/test','/tmp')
    stdin, stdout, stedrr = ssh.exec_command("sudo python /tmp/test")
    r = stdout.read()
    scp.close()
    ssh.close()
    

    B 스크립트를 통해 paramiko scpclient로 다른 서버로 A스크립트를 가져가서 exec_command로

    A 스크립트 실행 후 해당 내용을 다시 로컬에서 출력시키면 아래와 같은 메시지가 뜹니다.

    which: no fdisk in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin)
    

    환경 변수와 관련된 내용인 것 같은데 무슨 문제인지 감이 잡히질 않네요. ㅠㅠ

    고수님들 도와주세요..!

  • 프로필 파이썬님의 편집
    날짜2020.04.24

    파이썬 exec_command 질문



    (A 스크립트)

    whereis = os.popen("which fdisk")

    print(whereis.read())


    위 A 스크립트를 로컬에서 실행시키면 정상 출력이 되는데


    (B 스크립트)

    ssh = paramiko.SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ip,username=user,password=pw)

    scp = SCPClient(ssh.get_transport()) scp.put('/python/test','/tmp')

    stdin, stdout, stedrr = ssh.exec_command("sudo python /tmp/test")

    r = stdout.read()

    scp.close()

    ssh.close()


    B 스크립트를 통해 paramiko scpclient로 다른 서버로 A스크립트를 가져가서 exec_command로

    A 스크립트 실행 후 해당 내용을 다시 로컬에서 출력시키면 아래와 같은 메시지가 뜹니다.


    which: no fdisk in(/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin)


    환경 변수와 관련된 내용인 것 같은데 무슨 문제인지 감이 잡히질 않네요. ㅠㅠ

    고수님들 도와주세요..!