[英]Using ssh to login to linux terminal from windows and run command in a logged in shell
First of all, this may seem like a duplicate question but I have searched stack overflow/various other forum sites and still haven't managed to find a solution.首先,这似乎是一个重复的问题,但我已经搜索过堆栈溢出/各种其他论坛站点,但仍然没有找到解决方案。
A few example forum posts I have reviewed to prove I've done my research before asking a question:我已经查看了一些示例论坛帖子,以证明我在提问之前已经完成了研究:
There's hundreds more but I won't include them all.还有数百个,但我不会全部包括在内。
I essentially need a shell script to open a command prompt on windows, login to a remote linux system and run a command.我基本上需要一个 shell 脚本来在 windows 上打开命令提示符,登录到远程 linux 系统并运行命令。
I am aware this can be done with the following:我知道这可以通过以下方式完成:
start cmd /k ssh user@host ls
But the problem with the above is that the ssh connection is closed upon completion of the task.但是上面的问题是 ssh 连接在任务完成后关闭。 I am also aware I can keep the ssh connection open by adding:
我也知道我可以通过添加以下内容来保持 ssh 连接打开:
bash -l
in some cases.在某些情况下。
For my use case, I need to run a launch file for ROS (robot operating system) and for this I need to see the output from the command.对于我的用例,我需要为 ROS(机器人操作系统)运行启动文件,为此我需要从命令中查看 output。
And when attempting to run roslaunch launchFile.launch (in place of ls above):当尝试运行 roslaunch launchFile.launch(代替上面的 ls)时:
start cmd /k ssh user@host "roslaunch launchFile.launch"
the command prompt returns命令提示符返回
bash: roslaunch: command not found
I've obviously sanitised the specific name of my launch file but我显然已经清理了我的启动文件的具体名称但是
roslaunch launchFile.launch
runs perfectly if I login to the linux PC first:如果我先登录到 linux PC,运行完美:
ssh user@host
then run the command.然后运行命令。
I have achieved this exact use case on MacOS but I now need reimplement the same solution on windows:我已经在 MacOS 上实现了这个确切的用例,但我现在需要在 windows 上重新实现相同的解决方案:
osascript -e 'tell app "Terminal"
do script "ssh quantum@172.23.199.1 \n
roslaunch launchFile.launch"
end tell'
Thanks in advance for any help or advice.在此先感谢您的帮助或建议。
Try this:尝试这个:
start cmd /k ssh user@host "/full/path/to/roslaunch launchFile.launch; exec /bin/bash"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.