amoffat / sh

Python process launching

Home Page:https://sh.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RFH: Unable to pipe `sudo` process to `sudo` process

jamincollins opened this issue · comments

I can't seem to find a way to handle piping a sudo process to another sudo process, as both need to ask for a password.

For example:

    sh.contrib.sudo("dd", "bs=4M", f"of=/dev/{lvm_group}/{name}",
        _in=sh.contrib.sudo("rbd", "export", "--no-progress", volume, "-", _piped=True)
    )

I've also tried running the entire script as root with the following, but it never seems to make progress.

    sh.dd("bs=4M", f"of=/dev/{lvm_group}/{name}",
        _in=sh.rbd("export", "--no-progress", volume, "-", _piped=True)
    )

For now, I'm placing the above logic in a separate shell script that sh executes.

Bonus points would be a way to allow progress updates from the subprocess to display.

Try using sh.sudo directly:

sh.sudo.dd("bs=4M", f"of=/dev/{lvm_group}/{name}",
    _in=sh.sudo.rbd("export", "--no-progress", volume, "-", _piped=True)
)

The sh.contrib.sudo will always ask for a password every time it is executed.

but it never seems to make progress.

Are you sure it isn't just slow? Also, if you know progress is printed on stderr, you can redirect the output to sys.stderr or a callback.

If it is progressing but is just slow, there may be some more switches we can flip to make it faster. Let me know.

Closing. Feel free to reopen if you have time to get back to this issue.