Prev: (Partially SOLVED) Re: Wireless still not working
Next: How to reduce a debian system to a base system
From: Mike McClain on 19 Mar 2010 15:40 On Fri, Mar 19, 2010 at 06:45:15PM +0100, Sven Joachim wrote: > On 2010-03-19 18:19 +0100, Mike McClain wrote: > > > I've written a function to print elapsed time similar to /usr/bin/time > > but can be called at the beginning and end of a script from within > > the script. Occasionally I get an error: '8-08: value too great for base' > > It's caused by the difference in these 2 command strings but I can't for > > the life of me see what's going on. > > Apparently bash is treating the number as octal because it starts with a > leading 0. > > Sven In one case but not the other? What makes them treated differently? Mike -- Satisfied user of Linux since 1997. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org Archive: http://lists.debian.org/20100319190719.GA32017(a)playground.mcclains.net
From: Paul E Condon on 19 Mar 2010 15:50 On 20100319_101928, Mike McClain wrote: > I've written a function to print elapsed time similar to /usr/bin/time > but can be called at the beginning and end of a script from within > the script. Occasionally I get an error: '8-08: value too great for base' > It's caused by the difference in these 2 command strings but I can't for > the life of me see what's going on. > > now='09:07:16'; startHr=${now%%:*}; startHR=${startHr#*0}; echo $startHr; > 09 > > str=09; str=${str#*0}; echo $str; > 9 Try: bgn=$(date +%s) sleep 7 end=$(date +%s) echo "elapsed seconds = " $(( end - bgn )) Play with values other than '7'. To actually use in a script, replace the sleep command by whatever you want to measure the elapsed time for. Expressing elapsed time as HH:MM:SS requires a little more work. To write that script, use / for divide operator and % for remainder operator, like in C. -- Paul E Condon pecondon(a)mesanetworks.net -- To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org Archive: http://lists.debian.org/20100319194539.GH7246(a)big.lan.gnu
From: Chris Jackson on 19 Mar 2010 16:20 Paul E Condon wrote: > Try: > > bgn=$(date +%s) > sleep 7 > end=$(date +%s) > echo "elapsed seconds = " $(( end - bgn )) You might also want to experiment with: ps h -o etime $$ as long as you're happy with it only running under gnu. Prints the elapsed time for the shell. -- Chris Jackson Shadowcat Systems Ltd. -- To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org Archive: http://lists.debian.org/4BA3DAE2.7080208(a)shadowcat.co.uk
From: Josep M. on 29 Mar 2010 08:40 Hello. I found these somewhere time ago. check if is what You need: function timer() { if [[ $# -eq 0 ]]; then echo $(date '+%s') else local stime=$1 etime=$(date '+%s') if [[ -z "$stime" ]]; then stime=$etime; fi dt=$((etime - stime)) ds=$((dt % 60)) dm=$(((dt / 60) % 60)) dh=$((dt / 3600)) printf '%d:%02d:%02d' $dh $dm $ds fi } This is before the command t=$(timer) and this is after the command printf 'Elapsed time: %s\n' $(timer $t) example t=$(timer) copy /dev/null /dev/zero printf 'Elapsed time: %s\n' $(timer $t) Greetings Josep El vie, 19-03-2010 a las 10:19 -0700, Mike McClain escribió: > I've written a function to print elapsed time similar to /usr/bin/time > but can be called at the beginning and end of a script from within > the script. Occasionally I get an error: '8-08: value too great for base' > It's caused by the difference in these 2 command strings but I can't for > the life of me see what's going on. > > now='09:07:16'; startHr=${now%%:*}; startHR=${startHr#*0}; echo $startHr; > 09 > > str=09; str=${str#*0}; echo $str; > 9 > > Thanks, > Mike > -- > Satisfied user of Linux since 1997. > O< ascii ribbon campaign - stop html mail - www.asciiribbon.org > > -- To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org Archive: http://lists.debian.org/1269865700.29265.2.camel(a)mail.navegants.net
From: Mike McClain on 29 Mar 2010 19:40 Hi Josep, On Mon, Mar 29, 2010 at 02:28:20PM +0200, Josep M. wrote: > > I found these somewhere time ago. check if is what You need: > <snip> Thanks a lot. Though my error was pointed out as a typo and corrected a while back your solution using " date '+%s' " is much more elegant than what I had done. Mike PS: Since I posted to and read the list you needn't email me direct. MM -- Satisfied user of Linux since 1997. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org Archive: http://lists.debian.org/20100329213536.GB29806(a)playground.mcclains.net
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: (Partially SOLVED) Re: Wireless still not working Next: How to reduce a debian system to a base system |