Bug 160504 - sysutils/bsdstats: 300.statistics outputs an error message: expr: not a decimal number: ' 43905'
sysutils/bsdstats: 300.statistics outputs an error message: expr: not a decim...
Status: Closed FIXED
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s)
Latest
Any Any
: Normal Affects Only Me
Assigned To: Eitan Adler
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-09-06 07:00 UTC by koie
Modified: 2011-09-25 23:36 UTC (History)
0 users

See Also:


Attachments
file.diff (378 bytes, patch)
2011-09-06 07:00 UTC, koie
no flags Details | Diff
a.diff (677 bytes, patch)
2011-09-06 08:53 UTC, aakuusta
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description koie 2011-09-06 07:00:03 UTC
/usr/local/etc/periodic/monthly/300.statistics of sysutils/bsdstats reports with an error message since 2011-08-01, like this:

Doing login accounting:
        total                              343.90
        koie                               343.90
Posting monthly OS statistics to rpt.bsdstats.org
Posting monthly device statistics to rpt.bsdstats.org
Posting monthly CPU statistics to rpt.bsdstats.org
expr: not a decimal number: '   43905'
Posting monthly ports statistics to rpt.bsdstats.org

-- End of monthly output --

Fix: at the head of 300.statistics, IFS is set to newline.
I suspect /bin/sh has been changed for IFS or command substitution.

# sample script
set -x
IFS="
"
A="    123"
B=`expr $A + 1`
echo $B

% sh sample.sh
+ IFS='
'
+ A='    123'
+ expr '    123' + 1
expr: not a decimal number: '    123'
+ B=''
+ echo

%



Patch attached with submission follows:
How-To-Repeat: sudo /usr/local/etc/periodic/monthly/300.statistics
Comment 1 aakuusta 2011-09-06 08:53:40 UTC
KOIE Hidetaka <koie@suri.co.jp> writes:

> --- 300.statistics.orig	2011-09-06 14:30:53.572040919 +0900
> +++ 300.statistics	2011-09-06 14:32:56.860042305 +0900
> @@ -171,7 +171,7 @@
>  
>  
>  	# Make the request	
> -	string_length=`echo ${query_string} | wc -m` 
> +	string_length=`echo ${query_string} | wc -m | sed 's/^ *//'`
>  	string_length=`expr ${string_length} - 1`
>  
>  	echo "POST ${url_prefix}/scripts/report_ports.php HTTP/1.0

Why not just eliminate expr(1) rather than trying to conform to its quirks?

  from expr(1) man page:

     The syntax of the expr command in general is historic and
     inconvenient. New applications are advised to use shell arithmetic
     rather than expr.

and later

     ·   Leading white space and/or a plus sign before an otherwise
         valid positive numberic operand are allowed and will be
         ignored.

After r223881 this does not seem to be true

  $ expr -- ' 1' + 1
  expr: not a decimal number: ' 1'
  Exit 2

  $ expr -e -- ' 1' + 1
  2

default behavior is similar to `expr' from GNU coreutils

  $ gexpr -- ' 1' + 1
  gexpr: non-integer argument
  Exit 2

http://svnweb.freebsd.org/base?view=revision&revision=223881
Comment 2 koie 2011-09-06 09:37:52 UTC
I agree on using builtin arith, and I misunderstood the problem.
Comment 3 Eitan Adler freebsd_committer 2011-09-23 00:17:42 UTC
Responsible Changed
From-To: freebsd-ports-bugs->eadler

I'll take it.
Comment 4 Eitan Adler freebsd_committer 2011-09-25 21:31:00 UTC
State Changed
From-To: open->analyzed

-
Comment 5 dfilter freebsd_committer 2011-09-25 22:35:40 UTC
eadler      2011-09-25 21:35:26 UTC

  FreeBSD ports repository

  Modified files:
    sysutils/bsdstats    Makefile 
    sysutils/bsdstats/files 300.statistics.in 
  Log:
   - use shell arithmetic instead of expr
  
  PR:             ports/160504
  Submitted by:   KOIE Hidetaka <koie@suri.co.jp>
  Submitted by:   h h <aakuusta@gmail.com>
  Approved by:    bapt (mentor)
  
  Revision  Changes    Path
  1.62      +1 -1      ports/sysutils/bsdstats/Makefile
  1.45      +2 -2      ports/sysutils/bsdstats/files/300.statistics.in
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 6 Eitan Adler freebsd_committer 2011-09-25 23:36:01 UTC
State Changed
From-To: analyzed->closed

Committed. Thanks!