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.


#!/bin/bash
while [ 1 ]
do
# Your code goes here

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

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/

About SoCRaT

Systems Engineer, OSS & Linux Geek
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s