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/

Unknown's avatar

About Ahmed Tawfik

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

Leave a comment