Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exec commands that need sudo #49

Closed
andresv opened this issue Dec 9, 2022 · 2 comments
Closed

Exec commands that need sudo #49

andresv opened this issue Dec 9, 2022 · 2 comments

Comments

@andresv
Copy link
Contributor

andresv commented Dec 9, 2022

How to execute commands that need sudo, like:

let vec: Vec<u8> = exec.send_command("sudo systemctl stop some.service").unwrap();
println!("{}", String::from_utf8(vec).unwrap());
@1148118271
Copy link
Owner

Can try like this:

let vec: Vec<u8> = exec.send_command("echo 'password'|sudo -S rm -R /xxx/xxx").unwrap();

Or use the shell channel for interactive operations.

@andresv
Copy link
Contributor Author

andresv commented Dec 9, 2022

Thanks, yes echo 'password' | sudo -S somecmd works nicely.

@andresv andresv closed this as completed Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants