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
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
Hi Barun,
I think you have included [] around command. I tried that also but getting same error
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...
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
note that your line#7 is incorrect. The command you try to run is "l", not "ls"
hi In my post I have mentioned l only . I am not using ls . Still it is giving same error with l
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"])
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
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