0

I'm trying to use paramiko to connect and execute a remote script. In the below code, should the script in the client.exec_command can contain only linux commands (like ls -l)?

Code in Ubuntu BOX A:

client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

client.connect('ip-address of Ubuntu BOX B',22,'username','password')   <<<<< no issues till here....
stdin, stdout, stderr = client.exec_command('./shut.sh') 

for line in stdout:
   print 'This is the normal value ==> ' + line.strip('\n')

for line in stderr:
   print 'This is the err value ==> ' + line.strip('\n')

client.close()

When I run the above code, I get "awsstop command not found".

My remote script(shut.sh) contains ZPDT shutdown command, where I shutdown my zpdt system.

shut.sh in Ubuntu Box B

#!/bin/sh
awsstop

However, when I run the shut.sh locally thru the below python code, it works as expected.

test.py in Ubuntu Box B

import os
import subprocess
subprocess.Popen(["/home/ibmsys1/shut.sh"])

Is there anyway, we can trigger this script remotely OR Is it that, paramiko is not capable of doing this ? Do we have any other option ?

Matt
  • 1
  • Thank you. I did try all the options, but none worked for me. My question is, when the exec_command() gets executed, does it actually run the script in the host IP addr. that is used in the connect(........) ?? If it did, then the command not found error should not have occurred... – Matt Aug 26 '20 at 11:36
  • Yes it does execute the command on the host. And my answer to the linked question explains why the *"not found"* error can occur. – So are you claiming that if you replace the `awsstop` in the `./shut.sh` script with a full path to the `awsstop` (`/path/to/awsstop`), it still fails with *"not found"*? – Martin Prikryl Aug 26 '20 at 11:40
  • Yes. it still fails with "not found", though I give the complete path for awsstop. – Matt Aug 26 '20 at 12:18
  • Please try this - local command-line - no Python - 1) `ssh user@host ./shut.sh` 2) `ssh user@host awsstop` 3) `ssh user@host /full/path/awsstop` – Show us complete outputs. – Martin Prikryl Aug 26 '20 at 12:29
  • All the 3 commands throws the below error : error while loading shared libraries: libio_misc.so: cannot open shared object file: No such file or directory – Matt Aug 27 '20 at 06:14
  • Edit the complete output to your question. This way it's not clear if you get the error locally or remotely. Can you even connect with `ssh`? – Martin Prikryl Aug 27 '20 at 06:16
  • /usr/z1090/bin/awsstop: error while loading shared libraries: libio_misc.so: cannot open shared object file: No such file or directory . This is the complete error message I get. Also I checked the $PATH. It has the correct path set ----> /usr/z1090/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games – Matt Aug 27 '20 at 06:27
  • If .so file cannot be found, you have `LD_LIBRARY_PATH` set incorrectly. See https://stackoverflow.com/q/480764/850848#21173918 – Though I find it strange that you get a different error with `ssh` than with Paramiko. – Martin Prikryl Aug 27 '20 at 06:42
  • Thanks Martin for the clue. I did an export of LD_LIBRARY_PATH=/usr/z1090/bin:$LD_LIBRARY_PATH, in my script. so everytime the script runs, it sets this path. Its now resolved. – Matt Aug 27 '20 at 09:42
  • I'm still confused, as you original error message was *"awsstop command not found"*, what should not get resolved by setting `LD_LIBRARY_PATH`. – Martin Prikryl Aug 27 '20 at 09:47

0 Answers0