使用外部实用程序(plink)运行shell脚本-无法提供上下文

时间:2018-08-28 08:23:47

标签: bash shell unix plink

我在Unix环境中有一个Shell脚本,它本身会调用其他脚本(它们称为其他脚本),我想使用任务计划程序从Windows调用这些脚本。您可以想象这样的事情:

myMainScript.sh          (in /myFolder/myOtherFolder)

在此,我拨打以下电话:

#!/bin/bash
cd /myFolder/myOtherFolder       <-- this is to provide the context
cd otherSubFolder                <-- entering a subfolder
myOtherScript.sh                 <-- calling script in subfolder

请注意,myOtherScript.sh还将在同一子文件夹中调用其他脚本,这些脚本最终可能会调用其他脚本,由于它们是我无权使用的“官方”脚本,因此我无法对其进行修改。

当我从Shell控制台运行此脚本时,一切正常。 当我从plink运行此脚本时,它在第一个命令上引发了一个错误:

myOtherScript.sh: command not found

因此,我尝试提供绝对路径,而不是调用

myOtherScript.sh

...我打电话

/myFolder/myOtherFolder/otherSubFolder/myOtherScript.sh

在这种情况下,脚本已找到并运行,但是随后在myOtherScript.sh内部调用的脚本也遇到了同样的问题(我没有修改权限)。

我还尝试将myMainScript.sh的所有内容放入pushd + popd内(提供了上下文/myFolder/myOtherFolder),但还是没有运气。

谁能引导我正确的方向?

P.s。以防万一,这是我使用plink调用脚本的方式(该调用有效,因为我可以读取命令提示符的日志,显示该日志已记录到Unix环境):

"R:\tools\plink.exe" user@server-pw myPassword -sh -x "/myFolder/myOtherFolder/myMainScript.sh"

0 个答案:

没有答案