Closed aligajani closed 7 years ago
shell.run(["sudo", "su"], cwd = dir, encoding="utf-8")
When I run that, the script hangs indefinitely.
I want to be switching user to root so I can do stuff on my remote server.
It might be waiting for you to enter a password. What happens when you run the command yourself?
You can also try capturing the stdout and stderr when you run the command.
Actually, come to think of it, wouldn't running su
cause a new shell (as in a new Bash process or whatever you're using) to be spawned, so it's waiting for user input (in the case that you don't need to enter a password)?
When I run it myself on the server, it works.
How would I make this work with Spur ? I wish to login as root and do stuff.
I would suggest prepending sudo
to each command you want to run.
No, that doesn't work. I need to do sudo su to get myself as in root. I originally login as ubuntu. I can't login as root either as ec2 servers have a problem.
Why doesn't using sudo
on the individual commands work, especially if you expect sudo su
to work?
You can use sudo su
if you want, but that means you'll have to work out how to interact with the shell. Specifically, you'll have to use spawn()
and send appropriate strings into the stdin of the process, and parse the output of the shell (if you want to read the output of any of your commands).
I just did sudo su && cp /var/lib/redis/dump.rdb /home/ubuntu/
and it didn't copy.
I did this from the actual server not local. It just logged in as root. No error returned either.
I think you want to run sudo cp /var/lib/redis/dump.rdb /home/ubuntu/
.
Thank you. Yes.
I ran this now sudo su -c 'cp /var/lib/redis/dump.rdb /home/ubuntu/'
.
Works.
I'll need a few more details to be able to understand your issue. What code are you using? What results are you seeing? What results do you expect?