miscset.sh.run

miscset.sh.run(cmd, remote=None, user=None, piped=True, env=None)[source]

Run a (series of) shell command(s) as user at a host.

Wraps the subprocess.run method by adding features like:

  • send command as standard input to a runner, which is either
    • the local shell bash -s of the current user

    • the local shell using a different user with sudo -u <user>, or

    • the remote shell using a specified user login at a host via ssh <user>@<host>

  • supply environment paths exported in the shell prior to executing the command

  • return error code, stdout, stderr to a logger from the logging module as debug message

Parameters
  • cmd (str) – A string used as shell command.

  • remote (str) – A name of a remote server, if given ssh is invoked.

  • user (str) – A user name to connect with ssh to a remote server or switch to using sudo for localhost.

  • piped (bool) – Enable using bash -s to pipe commands to shell.

  • env (str) – Folder paths to use and export in PATH shell variable.

Returns

An object holding args, returncode and stdout/stderr values

from the executed subprocess.

Return type

subprocess.CompletedProcess