使用 shell 脚本在远程机器上执行多个命令 [英] Multiple commands on remote machine using shell script

查看:25
本文介绍了使用 shell 脚本在远程机器上执行多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在远程机器上有一个 Java 程序 Desktop/testfolder/xyz.jar.它在同一文件夹中有一个配置文件.当我通过 SSH 连接到机器时,我会:

I have a Java program Desktop/testfolder/xyz.jar on a remote machine. It 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 read the configuration.

我想先进入那个文件夹,然后从那个文件夹运行程序.如果我这样做,则在 shell 脚本中

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?

推荐答案

试试这个:

ssh you@yours.com "cd /home && ls -l"

这篇关于使用 shell 脚本在远程机器上执行多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆