3

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

tobym
  • 212
  • 1
  • 8

1 Answers1

4

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.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • 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