Python Forum
unable to run unix command using spur
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unable to run unix command using spur
#1
Hi Experts ,
I am trying to run simple command but getting an error
import spur
import spur.ssh

try:
	shell = spur.SshShell(hostname="EDQDVTAPP01.XXXXXX.com",port=22,username="applogs",password="XXXXXX",missing_host_key=spur.ssh.MissingHostKey.accept)
	with shell:
		result = shell.run("ls")
		print (result)
except spur.ssh.ConnectionError as error:
	print (error.original_traceback)
	raise
Error:
Traceback (most recent call last): File "unix_server_test.py", line 25, in <module> result = shell.run("ls") File "C:\Users\pubhatia\AppData\Local\Programs\Python\Python36\lib\site-packages\spur\ssh.py", line 166, in run return self.spawn(*args, **kwargs).wait_for_result() File "C:\Users\pubhatia\AppData\Local\Programs\Python\Python36\lib\site-packages\spur\ssh.py", line 206, in spawn raise NoSuchCommandError(command[0]) spur.errors.NoSuchCommandError: Command not found: l. Check that l is installed and on $PATH
Reply
#2
try
import spur
import spur.ssh
 
try:
    shell = spur.SshShell(hostname="EDQDVTAPP01.XXXXXX.com",port=22,username="applogs",password="XXXXXX",missing_host_key=spur.ssh.MissingHostKey.accept)
    with shell:
        result = shell.run(["ls"])
        print (result)
except spur.ssh.ConnectionError as error:
    print (error.original_traceback)
    raise
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Hi Barun,

I think you have included [] around command. I tried that also but getting same error
Reply
#4
Yes, that is what I did. Are you sure it's the same error? Please, post the full traceback
According to docs, shell.run should get a list of strings. Also obviously from your error it starts to iterate over the argument that has been passed to run() - in your case it try to execute just l as command...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Hi expert,

As you said I have changed my code as follows but still getting error. How can I ensure before running any command I am hit that server .Till now I am trying to do this by running ls command

import spur
import spur.ssh

try:
	shell = spur.SshShell(hostname="EDQDVTAPP01.XXXXX.com",port=22,username="applogs",password="XXXXX",missing_host_key=spur.ssh.MissingHostKey.accept)
	with shell:
		result = shell.run(["l"])
		print (result)
except spur.ssh.ConnectionError as error:
	print (error.original_traceback)
	raise
Error:
Traceback (most recent call last): File "unix_server_test.py", line 25, in <module> result = shell.run(["l"]) File "C:\Users\pubhatia\AppData\Local\Programs\Python\Python36\lib\site-packages\spur\ssh.py", line 166, in run return self.spawn(*args, **kwargs).wait_for_result() File "C:\Users\pubhatia\AppData\Local\Programs\Python\Python36\lib\site-packages\spur\ssh.py", line 206, in spawn raise NoSuchCommandError(command[0]) spur.errors.NoSuchCommandError: Command not found: l. Check that l is installed and on $PATH
Reply
#6
note that your line#7 is incorrect. The command you try to run is "l", not "ls"
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
hi In my post I have mentioned l only . I am not using ls . Still it is giving same error with l
Reply
#8
There is no command "l". How do you expect to run non-existing command? You claim you want to run "ls":

(Sep-05-2018, 06:32 AM)purnima1 Wrote: Till now I am trying to do this by running ls command

line# 7 should be
        result = shell.run(["ls"])
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#9
hi All,

I am getting same error.

import spur
import spur.ssh

try:
	shell = spur.SshShell(hostname="EDQDVTAPP01.XXXXX.com",port=22,username="applogs",password="XXXXX",missing_host_key=spur.ssh.MissingHostKey.accept)
	with shell:
		result = shell.run(["ls"])
		print (result)
except spur.ssh.ConnectionError as error:
	print (error.original_traceback)
	raise
	
Error:
Traceback (most recent call last): File "unix_server_test.py", line 25, in <module> result = shell.run(["ls"]) File "C:\Users\pubhatia\AppData\Local\Programs\Python\Python36\lib\site-packages\spur\ssh.py", line 166, in run return self.spawn(*args, **kwargs).wait_for_result() File "C:\Users\pubhatia\AppData\Local\Programs\Python\Python36\lib\site-packages\spur\ssh.py", line 206, in spawn raise NoSuchCommandError(command[0]) spur.errors.NoSuchCommandError: Command not found: ls. Check that ls is installed and on $PATH
Reply
#10
the obly thing that comes to my mind is try to replace line#7 with
shell.run(["sh", "-c", "echo $PATH"])
and see if everything is OK with $PATH
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pyspark sql unable to recognize SQL query command cpatte7372 6 16,635 Jul-31-2018, 04:17 PM
Last Post: micseydel
  How to run unix command in python soubalaji 1 3,225 Jan-11-2018, 07:16 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020