首页 > 解决方案 > 使用外部实用程序 (plink) 运行 shell 脚本 - 无法提供上下文

问题描述

我在 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),但仍然没有运气。

谁能引导我正确的方向?

Ps 以防万一,这是我调用脚本的方式plink(调用有效,因为我可以阅读命令提示符的日志,表明它已记录到 Unix 环境):

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

标签: bashshellunixplink

解决方案


推荐阅读