Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.)

share|improve this question
up vote 2 down vote accepted

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
19506 19506 19506 ?        00:00:00 sh

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

share|improve this answer
Perfect, thanks! – ecatmur Mar 20 '13 at 18:13

You'll probably want to do an expect script. Example with SVN:


share|improve this answer
That doesn't work; expect runs commands interactively. – ecatmur Mar 20 '13 at 16:39
Interactively in what sense? In the sense that it requires input from the user? If that's what you mean, there wouldn't be much point in expect existing in that case. One example I use it for is on Solaris the passwd command doesn't have a --stdin option so I have a cronjob set up that executes an expect script that wraps around passwd to feed it a random password for an account. No human interaction required. It's my understanding that this is the user's requirement. I could have misunderstood though. – Bratchley Mar 20 '13 at 18:31
Actually the more I re-read this, the more I realize I did misunderstand what you were going for. Apologies. – Bratchley Mar 20 '13 at 18:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.