[英]How to run a shell script within another shell script on a different server?
I created a shell script (Script 1) that I need to execute in server A;我创建了一个需要在服务器 A 中执行的 shell 脚本(脚本 1); using Script 1, I need to execute another shell script (Script 2) that resides in Server B.
使用脚本 1,我需要执行驻留在服务器 B 中的另一个 shell 脚本(脚本 2)。
I am able to do so with the following line:我可以使用以下行来做到这一点:
result=$(ssh ServerB /path/to/script/Script2.sh 2020-01-01 2020-03-12)
The problem is that Script 2, which I do not have edit access, calls another shell script using ./Script3 , I am getting an error stating问题是我没有编辑权限的脚本 2 使用 ./Script3 调用另一个 shell 脚本,我收到一个错误说明
"./Script3 : Not found"
I believe the reason behind that is that it is looking for ./Script3 within Server A, rather than looking for it in Server B我相信这背后的原因是它在服务器 A 中寻找 ./Script3,而不是在服务器 B 中寻找它
How should I execute script 1 to avoid this?我应该如何执行脚本 1 以避免这种情况?
Thanks in advance提前致谢
It's looking for it in the .
它正在寻找它
.
directory on Server B. Since you didn't change directory, the current directory is your home directory, not the directory containing the scripts.服务器 B 上的目录。由于您没有更改目录,因此当前目录是您的主目录,而不是包含脚本的目录。 Either change
Script2.sh
to use the full path to Script3
instead of ./Script3
, or you should change to the directory containing the scripts before running them.更改
Script2.sh
以使用Script3
的完整路径而不是./Script3
,或者您应该在运行脚本之前更改为包含脚本的目录。
result=$(ssh ServerB 'cd /path/to/script; ./Script2.sh 2020-01-01 2020-03-12')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.