writing a timer

Hi!,

My shell script takes a quite a long time to execute.. Nothing appears on the screen during this period.. User are left guessing... whats going on????????????

Any ideas on how to create a small timer script which print a word on screen say " wait.. Program running" after every 10 seconds till the the script has executed??

I have written a small function like:

timer()
{
while 1
do
if [ $PROG_STAT = 1 ]
then
echo ".." >$CUR_DEVICE
sleep 4
else
exit 1
fi
done
}

I am setting $PROG_STAT =0 at the end of the program.

I am calling the timer script to run in background before calling the main script.

but it doesnt seem to work properly..

How about a series of dots indicating the process is going on?
Here's the code.

#!/bin/bash
dots()
{
while true
do
echo -e ".\c"
sleep 2
}

clear
echo -e "Processing.Please Wait"
dots &
BG_PID=$!
#Here u can execute the process which is taking some time
<command to execute>
kill $BG_PID
echo "Complete"

Chill
:slight_smile:

A twirling bar

function rotate
{
# PURPOSE: This function is used to give the end user some feedback that 
# 	"something" is running.  It gives a line twirling in a circle.
#	This function is started as a background process. Assign its' PID
#    to a variable using:
#
#             rotate &      # To start 
#             ROTATE_PID=$! # Get the PID of the last background job
#
#       At the end of execution just break out by killing the $ROTATE_PID
#       process. We also need to do a quick "cleanup" of the left over 
#       line of rotate output. 
#
#           FROM THE SCRIPT:
#             kill -9 $ROTATE_PID
#             echo "\b\b   "

INTERVAL=1     # Sleep time between "twirls"
TCOUNT="0"	    # For each TCOUNT the line twirls one increment

while :        # Loop forever...until this function is killed
do
	TCOUNT=`expr $TCOUNT + 1`   # Increment the TCOUNT

	case $TCOUNT in
		"1")	echo '-'"\b\c"
			sleep $INTERVAL
			;;
		"2")	echo '\\'"\b\c"
			sleep $INTERVAL
			;;
		"3")	echo "|\b\c"
			sleep $INTERVAL
			;;
		"4")	echo "/\b\c"
			sleep $INTERVAL
			;;
		*)	TCOUNT="0" ;;  # Reset the TCOUNT to "0", zero.
	esac
done
} # End of Function - rotate

or dots...

function dots
{
     while true
     do
          echo ".\c"
     done
}

Folks,

thanks for your help..

Google's rotate script needs some correction..

Here is the corrected "case" statement:

case $TCOUNT in
"1") echo '-'"\b\c"
sleep $INTERVAL
;;
"2") echo '\ '"\b\b\c"
sleep $INTERVAL
;;
"3") echo "|\b\c"
sleep $INTERVAL
;;
"4") echo "/\b\c"
sleep $INTERVAL
;;
*) TCOUNT="0" ;; # Reset the TCOUNT to "0", zero.
esac

In my KSH, echo takes the preceding "\" as the escape sequence and prints \b and the final output is something like
\b\b\b\b\b\b\b\b\b\bComplete