简体   繁体   English

使用 ssh 从 windows 登录到 linux 终端并在登录的 shell 中运行命令

[英]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.

相关问题 在Linux上,如何以不同的登录名从终端外壳运行GUI应用程序? - On Linux, how do I run a GUI app from a terminal shell under a different login? 使用Java程序在Linux终端中运行命令? - Run command in linux terminal using java program? 从终端Linux运行jedit单个命令 - run jedit single command from terminal linux 从TypeScript运行任何Linux终端命令吗? - Run any Linux terminal command from TypeScript? 默认文件以Mac,Linux和Windows结尾,可在外壳/终端中运行可执行文件 - Default file ending in Mac, Linux and Windows to run executable in the shell/terminal 在Linux终端中,如何使用gnome-terminal打开ssh会话并在ssh会话中键入bash命令 - In linux terminal how to open a ssh session and type bash command inside the ssh session using gnome-terminal 使用ssh和shell从另一个PHP脚本在linux服务器中运行php脚本 - Run php script in linux server from another php script using ssh and shell 如何从Linux终端使用./运行python? - How to run python using ./ from Linux terminal? 从Linux终端启动Web浏览器(使用ssh) - Launching Web Browser from Linux Terminal (using ssh) 如何使用 shell 脚本生成一个新终端并在其上运行一些命令? - How to spawn a new terminal and run some command on that using a shell script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM