Super User is a question and answer site for computer enthusiasts and power users. 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

If I start a watch command in the background, it stops. Bringing the job to the foreground makes it run again, but I want this to run in the background.

$ watch ./do-something.sh &
[1] 97673
[1]+  Stopped                 watch ./do-something.sh

I expect this job to be running in the background, but it isnt

$ bg 1
[1]+ watch ./hello.sh &
[1]+  Stopped                 watch ./hello.sh

That doesn't do anything either. Starting the job in the foreground and moving in the background with Ctrl-Z and "starting" it with bg 1 doesn't work either.

Is this a "feature" of watch? I just want to periodically run something, every few seconds, and I don't particularly care about the output. (cron is not the right tool for this, fwiw).

share|improve this question
up vote 2 down vote accepted

I just want to periodically run something, every few seconds, and I don't particularly care about the output. (cron is not the right tool for this, fwiw).

And neither is watch. It's designed for interactively monitoring the output of some command – it will refuse to run in background if it cannot control the terminal, like any other interactive program.

Try something simpler:

while sleep 2; do ./do-something.sh; done &

Oh, and cron would be the right tool to do this – that's its only job, after all. There's only the limitation of not being able to specify jobs with second precision.

share|improve this answer
    
Thanks for the tip; that's a good answer. I also piped stdout and stderr to /dev/null since I wasn't interested in the output. – tobym Dec 14 '11 at 20:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .