Shopean1951 Shopean1951 - 1 year ago 73
Bash Question

Linux - Do a command repeatedly for a certain length of time

I know what the command watch -n does. I would like to do something like the following:

watch -n 5 "ls" //Do this for 30 minutes, then stop.

Essentially I want to repeat a command every 5 seconds, then stop after 30 minutes has passed. I'm missing the stop 30 minutes part. What command should I use to achieve this?


Answer Source

Use timeout:

timeout 1800 watch -n 5 "ls" 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download