Unix Commands Failing with "Command Not Found" in Python Paramiko exec_command
When executing Unix commands using Python's Paramiko exec_command, it's possible to encounter an error such as "
Underlying Cause
The cause lies in the default behavior of SSHClient.exec_command, which doesn't run a "login" shell and doesn't allocate a pseudo terminal for the session. As a result, different startup scripts may run and specific environment variables might not be set.
Possible Solutions
To resolve this, several approaches can be taken:
bash --login -c "sesu test"
PATH="$PATH;/path/to/sesu" && sesu test
stdin,stdout,stderr = ssh.exec_command('sesu test', get_pty=True)
Additional Considerations
Refer to these resources for further insights:
The above is the detailed content of How to Fix \'Command Not Found\' Error in Python Paramiko exec_command?. For more information, please follow other related articles on the PHP Chinese website!