How To Write Infinite Loop in Bash

By Angsuman Chakraborty, Gaea News Network
Sunday, November 18, 2007

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


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

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

For example I used this code to write a bash script to monitor long running mysql queries.

Discussion

Merle
June 8, 2008: 9:28 pm

Thanks, worked great.


Rob
YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :