Execute a bash function every 5 seconds but let the rest of the script run

Viewed 1640

I have a script where i need to run a spicific function at certian intervals while the rest of the script executes normally.

For example... I want to get disk data every hour while the rest of the scripts gathers process data every second...

Here I have a basic script to test this but its not working as expected...

#!/bin/bash

function test () {
echo "This line should print all the time..."
}

function test2 () {
echo "This line should only print every 3 seconds..."
sleep 3
}

while :
do 
   test &
   test2
done

Any help would be.... helpful :-D

Thanks!

2 Answers
Related