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
  • 2
  • 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.

grawity
  • 501,077