Register
It is currently Thu Nov 27, 2014 2:13 am

Elapsed time in seconds


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sun Jul 08, 2007 3:11 am   

Joined: Sun Jul 08, 2007 2:25 am
Posts: 4
Location: Bucharest
I have written a simple script to show the elapsed time in seconds. The program will exit when any key is pressed. I use this as a simple (and rough) counter in order to monitor some external events.

#!/bin/bash

start_time=$( date +"%s" ) #initial time

while true
do
let elapsed_time=$( date +"%s" )-start_time
echo -en "\rElapsed time: $elapsed_time sec."
read -s -n1 -t1 #no echo, read a single char, wait one second
if [ "$?" -eq 0 ] #if a key is pressed exit
then
echo #new line before exiting
exit 0
fi
done


Top
 Profile WWW YIM  
 PostPosted: Tue Jul 10, 2007 4:45 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
you should also check out the "time" program. it's a shell keyword.
works like:
Code:
time cp file.iso other_dir/

it will output the time it took for the command to run.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP