Home > Software engineering >  Using ssh to login to linux terminal from windows and run command in a logged in shell
Using ssh to login to linux terminal from windows and run command in a logged in shell

Time:05-07

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.

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. I am also aware I can keep the ssh connection open by adding:

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.

And when attempting to run roslaunch launchFile.launch (in place of ls above):

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:

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:

osascript -e 'tell app "Terminal"
     do script "ssh [email protected] \n
     roslaunch launchFile.launch"
end tell'

Thanks in advance for any help or advice.

CodePudding user response:

Try this :

start cmd /k ssh user@host "/full/path/to/roslaunch launchFile.launch; exec /bin/bash"
  • Related