import paramiko
import csv
# SSH 접속 정보
host = "remote_server_ip"
username = "user"
password = "password"
# SSH 접속
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=host, username=username, password=password)
# invoke_shell 을 사용해 명령어 전달
channel = client.invoke_shell()
channel.send("your_command")
time.sleep(30)
output = channel.recv(9999).decode('utf-8')
# output 을 csv 파일로 저장
file_name = "output.csv"
with open(file_name, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["output"])
for line in output:
writer.writerow([line.strip()])
# SSH 접속 종료
client.close()