Run a Linux command every X seconds forever using Watch command | OSTechNix
Have you ever wanted to run a command every few seconds automatically? Of course you can do this using a shell script or cron jobs. Alternatively, you can repeat a Linux command at a particular interval without having to manually run it. Here comes watch command in handy. Watch command can be used to execute a program every X seconds forever and it displays the outputs in the console. By default, the program is run every 2 seconds, Or you can define the time interval of your choice. It will keep running and displaying the respective results until you terminate the program by pressing CTRL+C or kill the process or force your system to reboot. Syntax: watch command Here is the set of five examples that explains where can you use watch command. Example 1: Let us display the output of the ‘uptime’ command: watch uptime Sample output: Every 2.0s: uptime Wed Feb 3 12:56:46 2016 12:56:46 up 2:14, 2 users, load average: 0.80, 0.87, 0.63 Here, Every
Fonte: Run a Linux command every X seconds forever using Watch command | OSTechNix