Multiple commands on remote machine using shell sc

2019-01-09 01:09发布

I have a java program Desktop/testfolder/xyz.jar on a remote machine.

It also has a configuration file on the same folder. When I SSH into the machine, I do:

"ssh user@remote java -cp Desktop/testfolder/xyz.jar Main"

The problem here is the configuration file is not in the path, as we are in the home folder so my program cannot readup the configuration.

So I want to first go into that folder and then run the program from that folder. In a shell script if I did this

"ssh user@remote cd Desktop/testfolder"
"java -cp xyz.jar Main"

it executes the first statement and when the second statement is run it runs on my current machine not the remote machine.

Can we do only one command or there are any other solutions for this ?

Thank you, Lalith

标签: ssh
3条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-09 01:13

Try something like this:

ssh you@yours.com "cd /home && ls -l"
查看更多
相关推荐>>
3楼-- · 2019-01-09 01:20

If you want to split your commands over multiple lines for the sake of readability, you could also pass the list of commands to the bash command as follows:

ssh user@remote.host bash -c "'
  cd Desktop/testfolder
  java -cp xyz.jar Main
'"
查看更多
可以哭但决不认输i
4楼-- · 2019-01-09 01:35

You could try separating the commands by a semicolon:

ssh user@remote "cd Desktop/testfolder ; java -cp xyz.jar Main"
查看更多
登录 后发表回答