Script doubt

Script doubt

am 31.01.2008 19:28:23 von apogeusistemas

Hi Unix Masters:

Can You help me with this script ?
I need get average used memory, but I=B4m getting negative values...
I think awk command can have any error...

#!/bin/ksh
memoria=3D`/usr/sbin/prtconf | grep Memory | awk '{ print $3 }'`
year=3D`date '+%Y'`
dia=3D`date '+%d'`
mth=3D`date +%m`
pmt=3D$((mth-1))
if [[ $pmt -eq "0" ]]
then
year=3D$((year-1))
pmt=3D12
fi
weekend=3D`cal $pmt $year | cut -c1-3,19-20 | awk 'substr($0, 1) ~/
[0-9]/ { print $0 }'`
past_month=3D`cal $pmt $year | cut -c1-20 | awk 'NR>2 { print $0 }'`
valid_days=3D$(echo $weekend $past_month | tr " " "\n" | sort -n | uniq -
u | tr "\n" " ")

if test -a /tmp/sar_I_mem??
then
rm /tmp/sar_I_mem??
fi

for I in `echo $valid_days`
do
if [[ ${#I} -eq 1 ]]
then
I=3D"0$I"
fi
sar -r -s 06:00 -e 19:10 -f /var/adm/sa/sa$I | awk '/:00:/&& $0 !~ /
free/ { print }' > /tmp/sar_I_mem$I
valor=3D`awk '{s+=3D$2;mem=3D$memoria}END{print mem-s*8192/1024/1024/NR}' /=

tmp/sar_I_mem$I`
echo "$I/$pmt/$year $valor"
done



/script
03/12/2007 -16460.7
04/12/2007 -15673.9
05/12/2007 -18615
06/12/2007 -20824.6
07/12/2007 -15020.3
10/12/2007 -14052.8
11/12/2007 -10111.7
12/12/2007 -14177.8

Thank You in advance.

Re: Script doubt

am 31.01.2008 23:24:26 von Bill Marcum

On 2008-01-31, apogeusistemas@gmail.com wrote:
>
>
> Hi Unix Masters:
>
> Can You help me with this script ?
> I need get average used memory, but I´m getting negative values...
> I think awk command can have any error...
>
> #!/bin/ksh
> memoria=`/usr/sbin/prtconf | grep Memory | awk '{ print $3 }'`
memoria=`/usr/sbin/prtconf | awk '/Memory/{ print $3 }'`
> year=`date '+%Y'`
> dia=`date '+%d'`
> mth=`date +%m`
> pmt=$((mth-1))
> if [[ $pmt -eq "0" ]]
> then
> year=$((year-1))
> pmt=12
> fi
> weekend=`cal $pmt $year | cut -c1-3,19-20 | awk 'substr($0, 1) ~/
> [0-9]/ { print $0 }'`
> past_month=`cal $pmt $year | cut -c1-20 | awk 'NR>2 { print $0 }'`
> valid_days=$(echo $weekend $past_month | tr " " "\n" | sort -n | uniq -
> u | tr "\n" " ")
>
> if test -a /tmp/sar_I_mem??
> then
> rm /tmp/sar_I_mem??
> fi
>
> for I in `echo $valid_days`
> do
> if [[ ${#I} -eq 1 ]]
> then
> I="0$I"
> fi
> sar -r -s 06:00 -e 19:10 -f /var/adm/sa/sa$I | awk '/:00:/&& $0 !~ /
> free/ { print }' > /tmp/sar_I_mem$I

> valor=`awk '{s+=$2;mem=$memoria}END{print mem-s*8192/1024/1024/NR}' /
> tmp/sar_I_mem$I`
Here is your problem. The variable "memoria" is not defined in awk, so
$memoria is equal to $0.

valor=`awk -v mem=$memoria '{s+=$2}END{print mem-s*8192/1024/1024/NR}'
/tmp/sar_I_mem$I`


> echo "$I/$pmt/$year $valor"
> done
>
>
>
> ./script
> 03/12/2007 -16460.7
> 04/12/2007 -15673.9
> 05/12/2007 -18615
> 06/12/2007 -20824.6
> 07/12/2007 -15020.3
> 10/12/2007 -14052.8
> 11/12/2007 -10111.7
> 12/12/2007 -14177.8
>
> Thank You in advance.

Re: Script doubt

am 01.02.2008 01:53:09 von apogeusistemas

On 31 jan, 20:24, Bill Marcum wrote:
> On 2008-01-31, apogeusiste...@gmail.com wrote:
>
> > Hi Unix Masters:
>
> > Can You help me with this script ?
> > I need get average used memory, but I=B4m getting negative values...
> > I think awk command can have any error...
>
> > #!/bin/ksh
> > memoria=3D`/usr/sbin/prtconf | grep Memory | awk '{ print $3 }'`
>
> =A0memoria=3D`/usr/sbin/prtconf | awk '/Memory/{ print $3 }'`
>
>
>
>
>
> > year=3D`date '+%Y'`
> > dia=3D`date '+%d'`
> > mth=3D`date +%m`
> > pmt=3D$((mth-1))
> > if [[ $pmt -eq "0" ]]
> > then
> > year=3D$((year-1))
> > pmt=3D12
> > fi
> > weekend=3D`cal $pmt $year | cut -c1-3,19-20 | awk 'substr($0, 1) ~/
> > [0-9]/ { print $0 }'`
> > past_month=3D`cal $pmt $year | cut -c1-20 | awk 'NR>2 { print $0 }'`
> > valid_days=3D$(echo $weekend $past_month | tr " " "\n" | sort -n | uniq =
-
> > u | tr "\n" " ")
>
> > if test -a /tmp/sar_I_mem??
> > then
> > rm /tmp/sar_I_mem??
> > fi
>
> > for I in `echo $valid_days`
> > do
> > if [[ ${#I} -eq 1 ]]
> > then
> > I=3D"0$I"
> > fi
> > sar -r -s 06:00 -e 19:10 -f /var/adm/sa/sa$I | awk '/:00:/&& $0 !~ /
> > free/ { print }' > /tmp/sar_I_mem$I
> > valor=3D`awk =A0'{s+=3D$2;mem=3D$memoria}END{print mem-s*8192/1024/1024/=
NR}' /
> > tmp/sar_I_mem$I`
>
> Here is your problem. =A0The variable "memoria" is not defined in awk, so
> $memoria is equal to $0.
>
> =A0valor=3D`awk -v mem=3D$memoria '{s+=3D$2}END{print mem-s*8192/1024/1024=
/NR}'
> =A0/tmp/sar_I_mem$I`
>
>
>
> > echo "$I/$pmt/$year =A0 $valor"
> > done
>
> > ./script
> > 03/12/2007 =A0 -16460.7
> > 04/12/2007 =A0 -15673.9
> > 05/12/2007 =A0 -18615
> > 06/12/2007 =A0 -20824.6
> > 07/12/2007 =A0 -15020.3
> > 10/12/2007 =A0 -14052.8
> > 11/12/2007 =A0 -10111.7
> > 12/12/2007 =A0 -14177.8
>
> > Thank You in advance.- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -

Thank You, Bill !