Gnuru.org
Productive Linux


Subscribe

 Subscribe via Feedburner in a reader

Enter your email address:

Delivered by FeedBurner


Login
Login:
Password:



Don't have an account?
Sign up to Gnuru.org
Forgot your password?

Stopwatch
1 December 2006 @ 23:11 GMT
by Paul

I searched high and low for a stopwatch that I could run on my laptop. Computers aren't the most accurate time pieces, it's true, but I didn't care. My task wasn't going to require any sort of accuracy.

Well, I couldn't find one. In fact the closest thing I found was the project management tool gnotime. This wasn't quite what I was looking for.

So, I wrote my own. The resolution is only in seconds and it's not very pretty. It suited my purpose though:

#!/bin/bash

BEGIN=$(date +%s)
while true; do
    NOW=$(date +%s)
    let DIFF=$(($NOW - $BEGIN))
    let MINS=$(($DIFF / 60))
    let SECS=$(($DIFF % 60))
    echo Time elapsed: $MINS:`printf %02d $SECS`
done




Posted by Guest User on 2007-12-31 08:36:22.

Cute idea.

I made two potentially useful changes, one functional, one aesthetic:

Functional - insert: usleep 10000 ...at the top of the loop to reduces update frequency from *very* fast to once every 100th of a second (massive reduction in CPU/power use)

Aesthetic - replace the echo command with: printf "\rTime elapsed: %d:%02d" $MINS $SECS ...to avoid scrolling.


Posted by Daniel Thompson on 2008-11-11 13:38:04.

this doesent work


Posted by hi on 2009-05-18 10:14:15.
Comments disabled