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.)
tty
confirming there is no terminal on stdin, and the "?" in the TTY column ofps
output which confirms there is no controlling tty for thesh
process (and anything running under it). – mr.spuratic Jan 05 '18 at 11:03setsid -w
. Example:setsid -w sh -c 'tty < /dev/tty'
givessh: 1: cannot open /dev/tty: No such device or address
(Note:/dev/tty
is your controlling tty). Without-w
setsid runs the process in parallel/background. – Tino Aug 11 '19 at 17:19