本文介绍了SSH:远程运行脚本并留在那里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在远程系统上运行一个脚本,然后希望留在那里.运行以下脚本:-

I wish to run a script on the remote system and then wish to stay there.Running following script:-

ssh user@remote logs.sh

这确实运行了脚本,但之后我又回到了我的主机系统.我需要留在远程一个.我试过了..

This do run the script but after that I am back to my host system. i need to stay on remote one. I tried with..

ssh user@remote logs.sh;bash -l

它以某种方式解决了问题,但仍然无法像命令那样重新登录:-

somehow it solves the problem but still not working exactly as a fresh login as the command:-

ssh user@remote

或者如果我可以在我的脚本中包含一些可以在脚本运行的同一目录中打开 bash 终端的内容会更好.请建议.

Or it will be better if i could include something in my script that would open the bash terminal in the same directory where the script was running. Please suggest.

推荐答案

试试这个:

ssh -t user@remote 'logs.sh; bash -l'

将两个命令传递给 ssh 都需要引号.-t 选项强制进行伪 tty 分配.

The quotes are needed to pass both commands to ssh. The -t option forces a pseudo-tty allocation.

考虑:

ssh user@remote logs.sh;bash -l

当 shell 解析这一行时,它会将其拆分为两个命令.第一个是:

When the shell parses this line, it splits it into two commands. The first is:

ssh user@remote logs.sh

这会在远程机器上运行 logs.sh.第二个命令是:

This runs logs.sh on the remote machine. The second command is:

bash -l

这会在本地机器上打开一个登录 shell.

上面添加了引号是为了防止 shell 以这种方式拆分命令.

The quotes were added above to prevent the shell from splitting up the commands this way.

这篇关于SSH:远程运行脚本并留在那里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 19:38