使用Shell脚本的远程计算机上的多个命令 [英] Multiple commands on remote machine using shell script

查看:69
本文介绍了使用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天全站免登陆