Python get_cmd_输出中的JumpSSh

2024-05-17 08:20:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从跳转服务器连接到远程服务器。它完美地连接到远程服务器,但是当我尝试在远程服务器上运行python脚本时,它说找不到目录。请帮忙

gateway_session = SSHSession('host',
                           'unman', password='password').open()
# from jump server, establish connection with a remote server
remote_session = gateway_session.get_remote_session('host',
                                                 'username',password='password')

print(gateway_session.get_cmd_output('python /Folder/test.py'))

Tags: from服务器目录脚本hostget远程server
1条回答
网友
1楼 · 发布于 2024-05-17 08:20:24

首先尝试检查您的位置:

print(gateway_session.get_cmd_output('pwd;ls -alrth; ls -alrth /'))

这样,您就知道在/处是否确实存在Folder

{a1}加上{a2}:

all I needed was to was separate the commands with a semi colon and run them using the same get output command.

OP补充道:

I just sshpass to a jump server from their, I sshpass to the remote on the same command in a shell script.

相关问题 更多 >