Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I needed a timer which will start at the very beginning of the script and stops at the end.Can anyone help me with that?

share|improve this question
2  
please, write a goal you want to achieve. to measure script working time use time command ( time ./script.sh ), to printout current time use date command and so on. –  rush Nov 4 '12 at 21:06
add comment

2 Answers

up vote 3 down vote accepted

If you want the duration in seconds, at the top use

start=$SECONDS

and at the end

duration=$(( SECONDS - start ))
share|improve this answer
add comment

You could use Linux's built-in time command. From the man page:

time COMMAND [arguments]

time determines which information to display about the resources used by the COMMAND from the string FORMAT. If no format is specified on the command line, but the TIME environment variable is set, its value is used as the format.

To time the cleanup.sh script, use:

$ time cleanup.sh
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.