[RULE] [Fwd: Re: Disk space used by a package?]

Jason Bechtel bechtel at freeshell.org
Tue Nov 16 18:52:14 EET 2004


You're on the right track...

I have a script called 'accumulate' that sits in /usr/local/bin
on my systems:

#!/bin/sh

# accumulate numbers from stdin until EOF
NUM=0
TOT=0
while read VAL
do
  DIGONLY=`echo "$VAL" | sed -e 's/[^0-9]//g' -e 's/^0*//'`
  [ -n "${DIGONLY}" ] || continue
  [ "${1}" = "-v" ] && echo "$DIGONLY"
  # using 'let' instead of 'expr' seems to reduce run time by over 50%
on ~5000 entries  --jmb
  #NUM=`expr $NUM + 1`
  let "NUM += 1"
  #TOT=`expr $TOT + $DIGONLY`
  let "TOT += $DIGONLY"
  [ "${1}" = "-v" ] && echo "$TOT"
done

# echo total to stdout
if [ "${1}" = "-v" ]; then
  echo "$NUM values accumulated"
  echo "Total = $TOT"
else
  echo "$TOT"
fi

# end of accumulate


If you run your rpm queries and pipe the output to this script, it will
give you a total:

rpm -qp --qf "[%{fssizes} \n]" $rpm | accumulate

Similarly, you could pipe the output from a bunch of queries:

~/.scripts/chkrpmsize.sh | accumulate

Just remove all of the extraneous debugging output from your script so
that only the sizes are printed.

Jason

PS:  I am using bash-2.05b-6mdk.


On Friday, Oct 22, 2004 at 10:30 PM, Ingo Lantschner typed:
> On Fri, 22 Oct 2004 20:05:28 +0200, Ingo Lantschner <ingo.lists at vum.at>  
> wrote:
> 
> 
> >All we would need is some function to add the many numbers from  
> >"ergebnis".
> I tried it with math-functions from bash. Problem: fssize seems to be an  
> integer.
> 
> This code:
>    #!/bin/sh
>    declare -i x   			 # x is integer
>    let x=0
>    let y=0       			       # y is string
>    echo " Int | String"
>    for rpm in `grep -v '^--' $1`
>    do
>       rpm -qp --qf "[%{fssizes} \n]" $rpm
>       x=`rpm -qp --qf "[%{fssizes}]" $rpm`
>       y=`rpm -qp --qf "[%{fssizes}]" $rpm`
>       echo "$x | $y"
>       echo "------------------------------------"
>    done;
> 
> 
> Shows this output:
> 
> $ ~/.scripts/chkrpmsize.sh  
> /sl/slinky-0.4.05/filesystem/scripts/3/all_packages.disc1 2> /dev/null
>  Int | String
> 1179325
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 5780536899596517376 | 11793250000000000000000
> ------------------------------------
> 190713288
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> -2202804535703371776 | 1907132880000000000000000
> ------------------------------------
> 
> etc.
> 
> Any idea pls. how to get numeric values from rpm/script which can be  
> calculated by bash?!
> 
> TIA, Ingo.
> 

_______________________________________________
Original home page of the RULE project: www.rule-project.org
Rule-list at rule-project.org
http://mail.rule-project.org/mailman/listinfo/rule-list_rule-project.org



This full static mirror of the Run Up to Date Linux Everywhere Project mailing list, originally hosted at http://lists.hellug.gr/mailman/listinfo/rule-list, is kept online by Free Software popularizer, researcher and trainer Marco Fioretti. To know how you can support this archive, and Marco's work in general, please click here