I want to time how long it takes to run some programmes and report the delta time in days, hours, minutes and seconds using a simple echo. Does someone have a simple bash script to do this?
Thanks,
siegfried
I want to time how long it takes to run some programmes and report the delta time in days, hours, minutes and seconds using a simple echo. Does someone have a simple bash script to do this?
Thanks,
siegfried
look into 'man time'
I found a simple stopwatch script, and then modified it to display the time on one line. (before it was echoing the time every loop in the terminal - a waste of space)
Enjoy!
#!/bin/bash
BEGIN=$(date +%s)
BACK="\b\b\b\b"
echo Starting Stopwatch...
while true; do
NOW=$(date +%s)
let DIFF=$(($NOW - $BEGIN))
let MINS=$(($DIFF / 60))
let SECS=$(($DIFF % 60))
#only echo count if its different than the last time
if [ "$DIFF" != "$OLDDIFF" ]
then
#backspace 4 times to reset stopwatch position
#The '-e' enables \b to be interpreted correctly
#The '-n' avoids the newline character at the end
echo -ne $BACK
echo -ne $MINS:`printf %02d $SECS`
fi
#define olddiff to current diff
let OLDDIFF=DIFF
done