python和ssh从x到Y

python和ssh从x到Y,python,shell,ssh,Python,Shell,Ssh,我使用的是ip x系统。我想从X使用ip y ssh到系统中,使用X在y shell上做一些工作,然后再次退出到X中。。使用python 我打算在x上运行以下python代码片段 if __name__ == "__main__": print "inside main of python file" command="ssh robert@172.1.1.2" output=subprocess.Popen(command, shell =False ) 当我运行这个

我使用的是ip x系统。我想从X使用ip y ssh到系统中,使用X在y shell上做一些工作,然后再次退出到X中。。使用python

我打算在x上运行以下python代码片段

if __name__ == "__main__":
    print "inside main of python file"
    command="ssh robert@172.1.1.2"
    output=subprocess.Popen(command, shell =False )
当我运行这个时,我希望新的shell将在当前shell上打开,然后我可以继续使用172.1.1.2。。但是,我发现在完成172.1.1.2的ssh之后,我当前的shell已经损坏


我想我做错了什么

如果您希望通过ssh运行shell命令,那么最好使用“fabric”,假设您将创建一个重复任务的python+shell脚本。在任何情况下,您都可以通过IPython运行fabric任务,获得访问权限,并从IPython本身执行任何基于shell的活动

但是,如果您需要Bash/*SH shell访问,那么最好使用expect在远程服务器上执行登录并创建shell