Tuesday, August 18, 2009

How To Write Infinite Loop in Bash

This is how you create an infinite loop in bash to run a piece of code infinitely at defined intervals.

while [ 1 ]
# Your code goes here

# Modify sleep time (in seconds) as needed below
sleep 2

I needed such code to monitor the size of a file every 2 seconds.

Source: http://blog.taragana.com/index.php/archive/how-to-write-infinite-loop-in-bash/

No comments: