실행할 원격 호스트에서 쉘 스크립트를 호출하는 Python 스크립트가 있습니다. 이 스크립트는 파일을 읽고 발견된 텍스트 패턴을 기반으로 일부 작업을 수행합니다. while 루프를 통해 파일을 읽으려고 하면 마지막 줄을 읽은 후에도 루프가 멈추는 것을 확인했습니다. Ctrl+C를 사용하여 Python 프로그램을 중단하면 다음 스택 추적이 표시됩니다.
address.py
ssh_command = [
'ssh',
'{}@{}'.format('user', i),
'bash', '/tmp/checks.sh'
]
ssh_command.append(i)
# Execute the SSH command
try:
subprocess.run(ssh_command, check=True)
except subprocess.CalledProcessError as e:
print('ERROR: Script execution failed with error code:', e.returncode)
check.sh
while read line; do
if [[ $line =~ $pattern1 ]]; then
echo -e "${line}\n${append_text}" | sudo tee -a "$file_path_tmp_new"
elif [[ $line =~ $pattern2 ]]; then
echo -e "${line}\n${append_text}" | sudo tee -a "$file_path_tmp_new"
elif [[ $line =~ $pattern0 ]]; then
echo -e "${line}\n${append_text}" | sudo tee -a "$file_path_tmp_new"
else
echo "$line" | sudo tee -a "$file_path_tmp_new"
fi
done < "$file_path_tmp"
산출:
^CTraceback (most recent call last):
File "adr.py", line 58, in <module>
subprocess.run(ssh_command, check=True)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 495, in run
stdout, stderr = process.communicate(input, timeout=timeout)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1020, in communicate
self.wait()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1083, in wait
return self._wait(timeout=timeout)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1806, in _wait
(pid, sts) = self._try_wait(0)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1764, in _try_wait
(pid, sts) = os.waitpid(self.pid, wait_flags)
KeyboardInterrupt
여기서 무엇이 잘못될 수 있는지에 대한 도움이 필요하십니까? 티아