0% found this document useful (0 votes)
17 views1 page

Inaccurate Bash Timer Script

This document discusses a bash script timer that is not accurate for longer times like 12 hours. The script uses a for loop that runs the specified number of seconds by echoing the countdown and using osd_cat. For longer times like 12 hours, the loop runs over 40,000 times, adding overhead that makes the timer up to 10 minutes inaccurate compared to the real time elapsed.

Uploaded by

luciange
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Inaccurate Bash Timer Script

This document discusses a bash script timer that is not accurate for longer times like 12 hours. The script uses a for loop that runs the specified number of seconds by echoing the countdown and using osd_cat. For longer times like 12 hours, the loop runs over 40,000 times, adding overhead that makes the timer up to 10 minutes inaccurate compared to the real time elapsed.

Uploaded by

luciange
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Timer in bash script not accurate when using it ...

[Link]

Unix & Linux Stack Exchange works best with JavaScript enabled
sign up

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.

log in

tour

Take the 2-minute tour

help

Timer in bash script not accurate when using it with longer times
#!/bin/bash
# get user input
ZENITY1=$(zenity --entry --text '

1m:

60s\n

5m:

300s\n10m:

600s\n15m:

900s\n20m: 1200s\n25m: 1500s\n30m: 1800s\n35m: 2100s\n40m: 2400s\n45m: 2700s\n50m:


3000s\n55m: 3300s\n

1h: 3600s' --entry-text "Input only int in seconds!" --title

"Timer")
# put starting date in variable
STARTTIME=$(date)
# audit/check user input
WAITINGTIME=$(echo $ZENITY1 | egrep "[0-9]{1,}" -o)
if [ "$WAITINGTIME" == "" ]; then exit 1; fi
# main stopwatch
for i in `seq $WAITINGTIME -1 1`; do echo $i | osd_cat -A left -p top -i 100 -c
black -d 1; done
# time expired message
zenity --info --text="Time expired@\n$(date)\n\nStarted@\n$STARTTIME"

So this is the script that I have on my desktop. If I need to warn somebody for e.x.: "please warn me after 15 minutes". But if I use it in a
longer time, e.x.: 12 hours it's not very accurate! it could get ~10 minutes dierence to the real time... :\ Why is it?
/ bash

/ shell-script

edited May 20 '12 at 17:04


mtk
2,190

26

58

asked Oct 29 '11 at 17:34


LanceBaynes
2,850

24

101

213

1 Answer
If you nd it takes consistently too long, I guess you're seeing the overhead of fourty-odd
thousand executions of echo and osd_cat .
answered Oct 29 '11 at 18:24
Ulrich Schwarz
3,864

1 din 1

27

13.12.2014 19:15

You might also like