writing a timer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting writing a timer
# 1  
Old 06-22-2004
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..

Last edited by jyotipg; 06-22-2004 at 06:54 AM..
# 2  
Old 06-22-2004
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
:-)
# 3  
Old 06-22-2004
A twirling bar
Code:
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...
Code:
function dots
{
     while true
     do
          echo ".\c"
     done
}

# 4  
Old 06-23-2004
Thanks..

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Writing only timing statistics output of Timer to File

I'm running long integrations on a remote server, and I'm working in terminal in a tcsh shell. I'm looking to write ONLY the timing statistics to a file. For example: $time ls >timer.out writes both the files in my current directory & the timer statistics to the file timer.out. I only... (2 Replies)
Discussion started by: elemonier
2 Replies

2. UNIX for Dummies Questions & Answers

Timer

is there a timer function in unix without using C? for example i want to display a message after 5 seconds how do i do that? (2 Replies)
Discussion started by: khestoi
2 Replies

3. Shell Programming and Scripting

Timer

Is there a way to make a timer? E.g Please give the seconds... ... (6 Replies)
Discussion started by: aekaramg20
6 Replies

4. UNIX for Dummies Questions & Answers

timer interrupt

hello all since a process running in kernel mode cannnot be preempted by any other process what would be the status of Timer interrupt that occurs when the time quantum of a process is elapsed? thanks (2 Replies)
Discussion started by: compbug
2 Replies

5. UNIX for Advanced & Expert Users

Timer for VNC

Hello fellows, I am new in this forum, i would appreciate your assistance. I need a timming system for my vnc desktops (Cybercafe timer stuff). Each unix user login to my server only with vnc, and i want to write a program that can generate timer tickets and have control on the time used for... (1 Reply)
Discussion started by: foweja
1 Replies

6. Shell Programming and Scripting

VNC Timer

Hello fellows, I am new in this forum, i would appreciate your assistance. I need a timming system for my vnc desktops (Cybercafe timer stuff). Each unix user login to my server only with vnc, and i want to write a program that can generate timer tickets and have control on the time used for... (0 Replies)
Discussion started by: foweja
0 Replies

7. Shell Programming and Scripting

timer

Hi all, Wanted to a create a shell script ----------------------------------------------------------------------- 1) which when called will start a timer and wait for 48 hours. after 48 hours it will call some function(say XYZ) 2) Whenever this shell script is called (can be called... (3 Replies)
Discussion started by: k_oops9
3 Replies

8. AIX

how to implement timer

anyone can help me how to implement the timer on AIX? I tried with 'setitimer' and its related functions, but it does not work correctly,the program exited each time. thanks (2 Replies)
Discussion started by: Frank2004
2 Replies

9. Programming

generating timer

I'm trying generate an interrupt every 1 seconds using itimer and My clock is not running. This is what i did : printf("about to sleep for 1 second \n"); signal(SIGALRM, wakeup); //myTimer.it_interval.tv_sec=0; //myTimer.it_interval.tv_usec =0; ... (5 Replies)
Discussion started by: Confuse
5 Replies

10. Post Here to Contact Site Administrators and Moderators

reply timer

Neo, can u please shorten the reply timer to like 1 min or so. It is prolly just me but i end up passing on replying to posts due to i hate waiting for my timer to reset w/ a 2.5 mins wait. (2 Replies)
Discussion started by: Optimus_P
2 Replies
Login or Register to Ask a Question