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

时间:2018-01-25 14:36:28

标签: batch-file ssh putty plink

目标:通过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”会失败?

1 个答案:

答案 0 :(得分:2)

这个问题部分涉及:
Script via Plink in .bat behaves differently

因此,您可以在正常会话中特别尝试which poweroff,以查看poweroff所在的位置(可以是/sbin/poweroff)。然后在plink命令行中使用完整路径。

由于您的命令行即使使用-t开关也不起作用,您的SSH服务器必须在“exec”通道中执行命令(在命令行或使用{{1}时提供命令时使用} switch)与“shell”频道不同。这很不寻常。

您可以使用输入重定向强制-m使用“shell”通道(就像在交互式会话中一样):

plink