更新时间:2023-12-04 22:46:40
在其他情况下,您正在使用交互式会话.
In the other cases, you are using interactive sessions.
当您在Plink的命令行上指定命令时,默认情况下Plink使用非交互式会话.
While the Plink uses non-interactive session by default, when you specify a command on its command-line.
您的脚本可能依赖于专门设置的某些环境变量(例如PATH
).
Your script probably relies on some environment variables (like PATH
) being set specifically.
很有可能仅针对交互式会话设置了变量.可能是因为在启动脚本中对它们进行了修改,而该启动脚本仅针对交互式会话执行(来源).
It's quite probable that the variables are set only for interactive sessions. Probably because they are modified in a startup script that is executed (sourced) for the the interactive sessions only.
解决方案是:
更正启动脚本以无条件地修改变量(即使对于非交互式会话也是如此).
Correct the startup scripts to modify the variables unconditionally (even for non-interactive sessions).
修改脚本,使其不依赖于环境变量.
Modify the script not to rely on environment variables.
或者您可以获取配置文件脚本,请参见无法使用PLINK从Windows使用ktutil命令运行Shell脚本.
Or you can source the profile script, see Unable to run shell script with ktutil command from Windows using PLINK.
使用-t
开关强制Plink使用交互式会话
Force the Plink to use the interactive session using the -t
switch
这不是推荐的解决方案,因为使用交互式会话自动执行命令会给您带来讨厌的副作用.例如,请参见有没有简单的方法来消除使用Python的Paramiko库进行SSH并从命令行的CLI提取输出时出现的垃圾值.远程机器?
This is not a recommended solution, as using the interactive session to automate a command execution can bring you nasty side effects. See for example Is there a simple way to get rid of junk values that come when you SSH using Python's Paramiko library and fetch output from CLI of a remote machine?
当使用"exec"通道执行命令时,更晦涩难懂的SSH服务器的行为也可能有所不同.请参见在Plink命令行上执行命令失败,并显示未找到" .
Some more obscure SSH servers can also behave differently when "exec" channel is used to execute the command. See Executing command on Plink command line fails with "not found".