Bootstrap FreeKB - Linux Commands - watch command (run a command once every x seconds)
Linux Commands - watch command (run a command once every x seconds)

Updated:   |  Linux Commands articles

Let's say you have a script named foo.sh that will append "Hello World" to a txt file, like this.

#!/bin/bash
echo "Hello World - The current date and time is `date +%Y-%m-%s %H:%M:%S`" >> log.txt

 

The watch command can be used to run this script every x seconds. In this example, the foo.sh script will be run every 5 seconds.

watch -n 5 bash foo.sh

 

Something like this should be displayed.

Every 5.0s: foo.sh

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 2ba0f0 in the box below so that we can be sure you are a human.