Closed nishantrangrej8 closed 9 years ago
You're creating a new shell each time, so the cd
command won't have any effect. You can just use the cwd
argument instead:
result = shell.run(["sh", "-c", "java -jar "], cwd="/tmp/")
result = shell.run(["sh", "-c", "ls -lrt"], cwd="/tmp/results")
However, cwd
isn't supported on minimal shells. Do you need to use a minimal shell type? If so, then you'll need to include the appropriate cd
command in the same program as the actual command you want to run:
result = shell.run(["sh", "-c", "cd /tmp/; java -jar "])
result = shell.run(["sh", "-c", "cd /tmp/results; ls -lrt"])
It is working for both. Thanks, mate.
I am trying to log on to machine. And I want to maintain the same session and execute multiple commands, one after another. Here's what I am trying to do in linux cd /tmp/ java -jar
cd /tmp/results
ls -lrt
and from the examples you have mentioned, I am trying this: shell = spur.SshShell(hostname="xx.xx.xxx.xxx", username="xxxxx", password="xxxxx", shell_type=spur.ssh.ShellTypes.minimal, missing_host_key=spur.ssh.MissingHostKey.accept) with shell: result = shell.run(["sh", "-c", "cd /tmp/"]) result = shell.run(["sh", "-c", "java -jar"])
result = shell.run(["sh", "-c", "cd /tmp/results"])
result = shell.run(["sh", "-c", "ls -lrt"])
print result.output
It is printing to all files in my directory when i log in. It is like I am logging in to shell everytime when i do shell.run. How can i just log on shell once, maintain a session and run multiple commands and close the session?