在 Plink 命令行上执行命令失败并显示“未找到”

2023-12-06

目标:通过 SSH 连接到 AntMiner,并发送poweroff命令。

命令:plink.exe -v -t -ssh antminer -l root -pw xxx poweroff

Connecting to 10.0.1.11 port 22  
We claim version: SSH-2.0-PuTTY_Release_0.70  
Server version: SSH-2.0-dropbear_2012.55  
Using SSH protocol version 2  
Using Diffie-Hellman with standard group "group14"  
Doing Diffie-Hellman key exchange with hash SHA-1  
Host key fingerprint is:  
ssh-rsa 1039 xxx  
Initialised AES-256 SDCTR client->server encryption  
Initialised HMAC-SHA1 client->server MAC algorithm  
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm  
Using username "root".  
Sent password  
Access granted  
Opening session as main channel  
Opened main channel  
Allocated pty (ospeed 38400bps, ispeed 38400bps)  
Started a shell/command  
sh: poweroff: not found  
Server sent command exit status 127  
Disconnected: All channels closed

所以连接工作正常,只是命令的发送出了问题。 这是应该发生的事情:(这次手动发送命令)

命令:plink.exe -v -t -ssh antminer -l root -pw xxx

Connecting to 10.0.1.11 port 22
We claim version: SSH-2.0-PuTTY_Release_0.70
Server version: SSH-2.0-dropbear_2012.55
Using SSH protocol version 2
Using Diffie-Hellman with standard group "group14"
Doing Diffie-Hellman key exchange with hash SHA-1
Host key fingerprint is:
ssh-rsa 1039 xxx
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "root".
Sent password
Access granted
Opening session as main channel
Opened main channel
Allocated pty (ospeed 38400bps, ispeed 38400bps)
Started a shell/command
root@antMiner:~# poweroff

Broadcast message from root@antMiner (pts/0) (Thu Jan 25 19:23:19 2018):

The system is going down for system halt NOW!
root@antMiner:~# Server unexpectedly closed network connection
FATAL ERROR: Server unexpectedly closed network connection

有人知道为什么通过 plink 发送命令“poweroff”失败吗?


这些问题涵盖了这一点:

  • .bat 中通过 Plink 执行的脚本的行为有所不同
  • sudo:使用 plink 时未找到命令

所以一个简单的解决方案是你可以尝试which poweroff在正常会话中,查看在哪里poweroff驻留(可以是/sbin/poweroff)。然后在你的中使用完整路径plink命令行。

尽管正确的解决方案是修复您的启动脚本。请参阅上面的链接。


由于您的命令行即使使用-t开关,您的 SSH 服务器必须在“exec”通道中执行命令(在命令行上提供命令或使用-mswitch)与“shell”通道中的不同。这是相当不寻常的。

你可以强制plink通过输入重定向来使用“shell”通道(如在交互式会话中):

echo poweroff| plink ...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Plink 命令行上执行命令失败并显示“未找到” 的相关文章

随机推荐