Invoke a command/script disconnected from the controlling terminal?

ecatmur

I'm investigating the behaviour of a script that is normally run as an automated process (e.g. cron, Jenkins). The script can (eventually) invoke commands that behave differently (seeking user input) when run interactively; for example, patch will ask what to do with a reversed patch, and svn will ask for passwords, but I need to see what happens when they're run non-interactively.

Persuading patch that it's non-interactive is fairly easy; I just need to redirect stdout to be a non-tty:

$ </dev/null > >(cat) /path/to/myscript --args

However svn will connect to the controlling terminal if it exists; editing the scripts to pass --non-interactive isn't really an option as this is coming from several levels deep and it'd be difficult to be certain I'd found every invocation.

Is there a way to invoke a script/command non-interactively, without a controlling terminal (so that /dev/tty doesn't exist)? I'd prefer stdout/stderr to still go to my terminal.

(I found the question Run script in a non interactive shell? but the answers to that discuss the differences between the cron and user environment; I've already eliminated all differences except non-interactivity.)

Stéphane Chazelas

You need to start another session not attached to a terminal, so for instance:

$ setsid sh -c 'tty; ps -jp "$$"; echo test' < /dev/null > log 2>&1
$ cat log
not a tty
  PID  PGID   SID TTY          TIME CMD
19506 19506 19506 ?        00:00:00 sh
test

See also the start-stop-daemon command found on some Linux distributions. There's also a daemon command.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I detach from a controlling terminal from the command line?

From Dev

Controlling tty / terminal output from other session / shell

From Dev

How can I print output whilst detached from controlling terminal?

From Dev

Concept of controlling terminal in Unix

From Dev

Understanding controlling terminal

From Dev

Understanding controlling terminal

From Dev

Concept of controlling terminal in Unix

From Dev

Controlling client terminal (linux)

From Dev

Is it the process that has a controlling terminal, or is it the session that has a controlling terminal?

From Dev

Is it the process that has a controlling terminal, or is it the session that has a controlling terminal?

From Dev

Performing redirection on a process not in the controlling terminal

From Dev

Performing redirection on a process not in the controlling terminal

From Dev

How to invoke Rebol interpreter from the "Android Terminal Emulator"?

From Dev

Can I invoke a GNOME screen-lock from the terminal?

From Dev

Invoke-WebRequest timeout if NIC 1 disconnected

From Dev

ways to verify a process no longer has a controlling terminal

From Dev

How to get the real name of the controlling terminal?

From Dev

monodevelop gdb failed to set controlling terminal

From Dev

More than one controlling terminal in one session?

From Java

Controlling State from outside of a StatefulWidget

From Dev

Controlling Window close from UserControl

From Dev

Controlling Spotify from another client

From Dev

Controlling Window close from UserControl

From Dev

Controlling component from backing bean

From Dev

Controlling ngVideo object from Controller

From Dev

Python for controlling Application from CLI

From Dev

Xamarin - disconnected from layout renderer

From Dev

what relations are between my current controlling terminal and `/dev/tty`?

From Dev

Does systemd not protect processes against acquiring a controlling terminal?

Related Related

  1. 1

    How do I detach from a controlling terminal from the command line?

  2. 2

    Controlling tty / terminal output from other session / shell

  3. 3

    How can I print output whilst detached from controlling terminal?

  4. 4

    Concept of controlling terminal in Unix

  5. 5

    Understanding controlling terminal

  6. 6

    Understanding controlling terminal

  7. 7

    Concept of controlling terminal in Unix

  8. 8

    Controlling client terminal (linux)

  9. 9

    Is it the process that has a controlling terminal, or is it the session that has a controlling terminal?

  10. 10

    Is it the process that has a controlling terminal, or is it the session that has a controlling terminal?

  11. 11

    Performing redirection on a process not in the controlling terminal

  12. 12

    Performing redirection on a process not in the controlling terminal

  13. 13

    How to invoke Rebol interpreter from the "Android Terminal Emulator"?

  14. 14

    Can I invoke a GNOME screen-lock from the terminal?

  15. 15

    Invoke-WebRequest timeout if NIC 1 disconnected

  16. 16

    ways to verify a process no longer has a controlling terminal

  17. 17

    How to get the real name of the controlling terminal?

  18. 18

    monodevelop gdb failed to set controlling terminal

  19. 19

    More than one controlling terminal in one session?

  20. 20

    Controlling State from outside of a StatefulWidget

  21. 21

    Controlling Window close from UserControl

  22. 22

    Controlling Spotify from another client

  23. 23

    Controlling Window close from UserControl

  24. 24

    Controlling component from backing bean

  25. 25

    Controlling ngVideo object from Controller

  26. 26

    Python for controlling Application from CLI

  27. 27

    Xamarin - disconnected from layout renderer

  28. 28

    what relations are between my current controlling terminal and `/dev/tty`?

  29. 29

    Does systemd not protect processes against acquiring a controlling terminal?

HotTag

Archive