나는 파이썬 프로그램 (아래)이 있고 내가 그것을 실행할 때 다음과 같은 오류 얻을 :stderr에서 오류가 발생했습니다. 어떻게 해결합니까?
% python SSH_Prog.py
About to connect...
stderr: ["bash: -c: line 0: unexpected EOF while looking for matching `''\n", 'bash: -c: line 1: syntax error: unexpected end of file\n']
pwd: []
stderr: ['watch: no process found\n']
pwd: []
^CTraceback (most recent call last):
File "SSH_Prog.py", line 32, in <module>
time.sleep(3)
KeyboardInterrupt
나는 아마 이스케이프 시퀀스와 함께 할 생각하고, 표준 입력에서 "\ n"문자 만을 나는 그것을 다루는 경험이 부족하다.
import os
import sys
import time
import paramiko
#from ssh import SSHClient
# Define remote machine
host="<ip>"
user="<usrnm>"
passw="<passw>"
client = paramiko.SSHClient()
#client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Try SSH connection, catch exception
#if not
print('About to connect...')
client.connect(host, username=user, password=passw)
# ForLoop to iterate through the interactions
for x in range(10):
xx = str(x)
# Commands to execute on local machine
f = os.popen3('tshark -i eth0 -f snmp -F pcapng -w ~/Desktop/traf_logs/n'+(xx))
# commands to execute on remote machine
stdin, stdout, stderr = client.exec_command("watch -n 0.1 'ps -p $(pgrep -d"," -x snmpd) -o rss= | awk '\''{ i += $1 } END { print i }'\'' >> ~/Desktop/mem_logs/mem_"+(xx)+";")
print "stderr: ", stderr.readlines()
print "pwd: ", stdout.readlines()
g = os.popen3('snmpget -v 2c -c communitystring <ip> sysContact.0')
time.sleep(3)
stdin, stdout, stderr = client.exec_command('killall watch;')
print "stderr: ", stderr.readlines()
print "pwd: ", stdout.readlines()
ff = os.popen3('killall tshark')
# terminate connection
client.close()
exit(0)
당신이 그것을 해결하기 위해 어떤 생각을 가지고 있습니까 : 여기
프로그램입니까?감사합니다.
'os.popen'과 패밀리를 사용하는 대신'subprocess.Popen'을 체크 아웃하십시오. 요즘 사용하는 것이 좋습니다 - 그건 단지 일반적인 논평 일뿐입니다. 문제의 해결책 일 필요는 없습니다 – mgilson
이것은'exec_command '내의'watch'가 올바른 프로세스를 찾을 수없는 이유와 관련이 있습니다. 부분적으로 실행하고 결과물이 있어야하는지 확인하십시오. –
실제로 무엇을 하려는지 설명하고,'ssh' 연결의 다른 끝에 도착하는 명령 줄이 어떤 모습인지 예상 할 수 있습니까? – abarnert