sudo:使用 plink 时找不到命令 [英] sudo: command not found while using plink
问题描述
您好,我创建了一个批处理文件 (run.bat),执行后在 plink 的帮助下将我连接到 UNIX 服务器.但问题从这一点开始,我必须在连接到我的服务器后执行一个脚本,该脚本包含一个命令 sudo -l.执行后,我收到了主题中提到的错误,谁能帮我解决这个问题??
Hi i have created a batch file (run.bat) that after execution connects me to UNIX server with help of plink. But issue starts from this point i have to execute a script after connection to my server the script contains a command sudo -l. After the execution i get the error as mentioned in subject can anyone help me on this issue ??
批处理文件-:
"C:\Program Files\PuTTY" plink -ssh -pw Tos@12Ts w44dvftyw@caa1607UX009.wvd.abcd.net /opt/sieb/w44dvftyw/run.sh
脚本文件(run.sh) -:
#!/bin/bash
sudo -l
它说
sudo:找不到命令
但是当我在 UNIX 服务器上正常运行我的脚本时,它运行没有问题.我在这里缺少什么以使其以这种方式工作,请帮忙.
But when i run my script normally on UNIX server it runs with no issues. What am i missing here to make it work this way please help.
推荐答案
~/.profile
或 ~/.bash_profile
等脚本负责设置当前用户的PATH
仅在登录 shell 上运行.
Scripts such as ~/.profile
or ~/.bash_profile
responsible for setting up the current user's PATH
are run only on login shells.
运行 sh -c 'somescript'
(由 ssh host 'somescript'
执行)既不是登录 shell,也不是交互式 shell;因此,它不会获得此类脚本的好处.
Running sh -c 'somescript'
(as performed by ssh host 'somescript'
) is neither a login shell, nor an interactive shell; thus, it does not gain the benefit of such scripts.
这意味着以这种方式运行的命令可能不存在对 PATH
(在您的情况下为 /usr/local/bin
)的添加.
This means that additions to the PATH
(in your case, /usr/local/bin
) may not be present with commands run in this way.
您的选择:
将您想要的 PATH 作为命令的一部分传递给远程运行.这可能看起来像:
Pass the PATH you want as part of the command to remotely run. This might look like:
plink -ssh user@host "PATH=/bin:/usr/bin:/usr/local/bin /opt/sieb/w44dvftyw/run.sh"
在您正在运行的脚本中嵌入一个工作值:
Embed a working value in the script you're running:
#!/bin/bash
PATH=/bin:/usr/bin:/usr/local/bin
# ...put the rest of your script here.
这篇关于sudo:使用 plink 时找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!