0

When I try to run a task with task spooler that requires sudo access like

ts sudo echo "hello world"

it doesn't ask for my password and exits with error 1

Alternatively, I have some tasks that may require my password during execution. How can I interact with it?

Eduardo Poiate
  • 1
  • 1
  • 1
  • 1

1 Answers1

1

What ts runs is not connected to a terminal. I assume you don't want to set up sudo to work without password. Then you need to provide your password without a terminal. This can be done with sudo -A:

From man 8 sudo:

-A
Normally, if sudo requires a password, it will read it from the user's terminal. If the -A (askpass) option is specified, a (possibly graphical) helper program is executed to read the user's password and output the password to the standard output. If the SUDO_ASKPASS environment variable is set, it specifies the path to the helper program. […]

Write a helper script. The script should just print your password. An example script is in this another answer of mine.

Then you can do this:

SUDO_ASKPASS="/path/to/helper/script" sudo whatever

With ts the right syntax is:

SUDO_ASKPASS="/path/to/helper/script" ts sudo whatever

It's up to you how the script knows the password. The password may be hardcoded (like in the example), stored in a file (the script would then just cat file), obtained by connecting to some agent or interactively from you (e.g. by displaying a GUI window; read How do I ask password by GUI prompt while using sudo in script?).

Securing the script (and the file, if any) is your concern now.

Note sudo may be configured not to work without a terminal.