通过Plink执行poweroff命令失败提示‘not found’的问题排查
poweroff fail when sent directly via Plink but work in an interactive shell? Great question! I’ve run into this exact issue with embedded devices like AntMiner before, and it all boils down to differences between interactive and non-interactive shell environments.
Let’s break down the root cause:
When you run plink.exe ... poweroff, Plink executes the command in a non-interactive, non-login shell. This type of shell doesn’t load the same configuration files that your interactive shell uses.
On most Linux-based mining devices like AntMiner, the poweroff binary is typically located in /sbin or /usr/sbin—directories that are added to your PATH environment variable only when you start an interactive shell (via files like ~/.bashrc, /etc/profile, or /etc/bash.bashrc).
In the non-interactive shell that Plink uses, the default PATH is much shorter and doesn’t include /sbin//usr/sbin, so the system can’t find the poweroff command, hence the sh: poweroff: not found error (exit code 127 is the standard code for "command not found").
When you log in manually via Plink (without appending the command), you get an interactive shell which loads those configuration files, updates your PATH, and lets you run poweroff without issues.
Fixes you can try:
Use the absolute path to
poweroff
First, find wherepoweroffis located by running this in your interactive shell:which poweroffIt’ll probably return something like
/sbin/poweroff. Then update your Plink command to use that full path:plink.exe -v -t -ssh antminer -l root -pw xxx /sbin/poweroffForce the shell to load interactive/login configurations
You can tell Bash (or whatever shell AntMiner uses) to run as a login shell, which will load the necessaryPATHsettings. Use this command:plink.exe -v -t -ssh antminer -l root -pw xxx bash -l -c "poweroff"(The
-lflag makes Bash act as a login shell, and-clets you pass the command to execute.)Manually add the required directory to
PATHbefore runningpoweroff
If you don’t want to use the absolute path, you can extend thePATHtemporarily in the same command:plink.exe -v -t -ssh antminer -l root -pw xxx export PATH=$PATH:/sbin && poweroff
内容的提问来源于stack exchange,提问作者Wannes

