您好,我创建了一个批处理文件(run.bat),执行后该文件在plink的帮助下将我连接到UNIX服务器。但问题从此时开始,我必须在连接到服务器后执行一个脚本,该脚本包含命令 sudo -l。执行后,我收到主题中提到的错误,任何人都可以帮助我解决这个问题吗??
批处理文件-:
"C:\Program Files\PuTTY" plink -ssh -pw Tos@12Ts <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c1b6f5f5a5b7a7b5b8b681a2a0a0f0f7f1f69499f1f1f8efb6b7a5efa0a3a2a5efafa4b5" rel="noreferrer noopener nofollow">[email protected]</a> /opt/sieb/w44dvftyw/run.sh
脚本文件(run.sh) -:
#!/bin/bash
sudo -l
它说
sudo: command not found
但是当我在 UNIX 服务器上正常运行脚本时,它运行没有问题。我在这里缺少什么才能使其以这种方式工作,请帮忙。
最佳答案
负责设置当前用户的 PATH
等脚本,例如 ~/.profile
或 ~/.bash_profile
仅在登录 shell 上运行.
运行sh -c 'somescript'
(由ssh host 'somescript'
执行)既不是登录shell,也不是交互式shell;因此,它无法从此类脚本中受益。
这意味着以这种方式运行的命令可能不会出现对PATH
(在您的情况下为/usr/local/bin
)的添加。
您的选择:
将您想要的路径作为远程运行命令的一部分传递。这可能看起来像:
plink -ssh user@host "PATH=/bin:/usr/bin:/usr/local/bin /opt/sieb/w44dvftyw/run.sh"
在您正在运行的脚本中嵌入工作值:
#!/bin/bash PATH=/bin:/usr/bin:/usr/local/bin # ...put the rest of your script here.
关于bash - 须藤: command not found while using plink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44702874/