Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

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.