Home > Article > Backend Development > Why Do Some Unix Commands Return \'not found\' Error in Python\'s Paramiko Exec_Command?
"not found" Error with Unix Commands in Python's Paramiko
When attempting to execute the command 'sesu' on a Unix server using Python's Paramiko exec_command, users may encounter the error message "sh: sesu: not found." This issue arises only with certain commands, such as 'sesu,' while other commands, like 'ls,' function as intended.
This error stems from a default behavior in SSHClient.exec_command, which does not run the shell in "login" mode and does not allocate a pseudo terminal. Consequently, the command execution may differ from an interactive SSH session, where certain startup scripts and environment variables are sourced or used.
Possible Solutions
The following solutions are recommended in order of preference:
/bin/sesu test
bash --login -c "sesu test"
PATH="$PATH;/path/to/sesu" && sesu test
stdin,stdout,stderr = ssh.exec_command('sesu test', get_pty=True)
The above is the detailed content of Why Do Some Unix Commands Return \'not found\' Error in Python\'s Paramiko Exec_Command?. For more information, please follow other related articles on the PHP Chinese website!