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 ?

10
  • 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... Commented Aug 26, 2020 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"? Commented Aug 26, 2020 at 11:40
  • Yes. it still fails with "not found", though I give the complete path for awsstop. Commented Aug 26, 2020 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. Commented Aug 26, 2020 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 Commented Aug 27, 2020 at 6:14

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.