Script error
am 06.12.2007 23:03:35 von apogeusistemas
Hi:
Can You tell me why this script works fine in Solaris10, but when I
transfer this script to
a Solaris 8 machine I get errors ?
# cat sar_cpu2
#!/bin/bash
set -x
clear
echo
LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24 25 26 27 28 29 30 31"
echo "Entre com os sabados, domingos e feriados a serem excluidos -
separados por espaco: "; read weekend_days
lav=`/usr/xpg4/bin/grep -vf <(echo $weekend_days | tr ' ' '\n') <(echo
$LA |tr ' ' '\n')`
echo " Entre com o endereco do arquivos sar binarios: " ; read
endereco
dias=`echo $lav | awk '{ print NF }'`
#echo $lav
#echo $endereco
#echo $dias
LINECOUNTER="1"
SAPATH="/tmp" # dir of your sa-files
SUM=(0,0,0,0)
DAYS="$dias" # number of days
HUNDRED="100"
rm /tmp/sa??
for I in $lav
do
#echo $I
sar -u -f $endereco/sa$I > /tmp/sa$I
#ls /tmp/sa??
done
while read FOO
do
SUM=(0,0,0,0)
for I in $lav
do
ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
case "${ELEMENT[1]}" in
[0-9]*)
let SUM[1]=${SUM[1]}=0
let SUM[2]=${SUM[2]}=0
let SUM[3]=${SUM[3]}=0
let SUM[4]=`${SUM[4]}`+${ELEMENT[4]}
;;
*)
NEWLINE="${ELEMENT[@]}"
;;
esac
done
case ${ELEMENT[1]} in
[0-9]*)
let AVG[1]=0
let AVG[2]=0
let AVG[3]=0
## let AVG[4]=${SUM[4]}/$DAYS
let AVG[4]=$HUNDRED-${SUM[4]}/$DAYS
## echo "${ELEMENT[0]} ${AVG[1]} ${AVG[2]} $
{AVG[3]} ${AVG[4]}"
## printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} $
{AVG[1]} ${AVG[2]} ${AVG[3]} ${AVG[4]}
printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} ${AVG[4]} $
{AVG[2]} ${AVG[3]} ${AVG[1]}
;;
*)
echo "$NEWLINE"
;;
esac
let LINECOUNTER=LINECOUNTER+1
done < "$SAPATH/sa01"
../sarcpu2
../sar_cpu2: let: AVG[4]=100-/2: syntax error: operand expected (error
token is "/2")
Re: Script error
am 06.12.2007 23:14:38 von Cyrus Kriticos
apogeusistemas@gmail.com wrote:
> [...]
> let SUM[4]=`${SUM[4]}`+${ELEMENT[4]}
> [...]
> let AVG[4]=$HUNDRED-${SUM[4]}/$DAYS
> [...]
>
> ./sar_cpu2: let: AVG[4]=100-/2: syntax error: operand expected (error
> token is "/2")
${SUM[4]} is empty. What's the purpose of ` ?
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Re: Script error
am 06.12.2007 23:15:12 von Janis Papanagnou
apogeusistemas@gmail.com wrote:
> Hi:
>
> Can You tell me why this script works fine in Solaris10, but when I
> transfer this script to
> a Solaris 8 machine I get errors ?
>
>
> # cat sar_cpu2
> #!/bin/bash
> set -x
> clear
> echo
>
> LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
> 23 24 25 26 27 28 29 30 31"
>
> echo "Entre com os sabados, domingos e feriados a serem excluidos -
> separados por espaco: "; read weekend_days
> lav=`/usr/xpg4/bin/grep -vf <(echo $weekend_days | tr ' ' '\n') <(echo
> $LA |tr ' ' '\n')`
> echo " Entre com o endereco do arquivos sar binarios: " ; read
> endereco
> dias=`echo $lav | awk '{ print NF }'`
> #echo $lav
> #echo $endereco
> #echo $dias
>
> LINECOUNTER="1"
> SAPATH="/tmp" # dir of your sa-files
> SUM=(0,0,0,0)
> DAYS="$dias" # number of days
> HUNDRED="100"
>
> rm /tmp/sa??
>
> for I in $lav
> do
> #echo $I
> sar -u -f $endereco/sa$I > /tmp/sa$I
> #ls /tmp/sa??
> done
> while read FOO
> do
> SUM=(0,0,0,0)
>
>
>
> for I in $lav
> do
> ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
>
> case "${ELEMENT[1]}" in
> [0-9]*)
> let SUM[1]=${SUM[1]}=0
> let SUM[2]=${SUM[2]}=0
> let SUM[3]=${SUM[3]}=0
> let SUM[4]=`${SUM[4]}`+${ELEMENT[4]}
?????
> ;;
> *)
> NEWLINE="${ELEMENT[@]}"
> ;;
> esac
> done
>
>
> case ${ELEMENT[1]} in
> [0-9]*)
> let AVG[1]=0
> let AVG[2]=0
> let AVG[3]=0
> ## let AVG[4]=${SUM[4]}/$DAYS
> let AVG[4]=$HUNDRED-${SUM[4]}/$DAYS
!!!!!
>
>
> ## echo "${ELEMENT[0]} ${AVG[1]} ${AVG[2]} $
> {AVG[3]} ${AVG[4]}"
>
> ## printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} $
> {AVG[1]} ${AVG[2]} ${AVG[3]} ${AVG[4]}
> printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} ${AVG[4]} $
> {AVG[2]} ${AVG[3]} ${AVG[1]}
> ;;
> *)
> echo "$NEWLINE"
> ;;
> esac
>
>
> let LINECOUNTER=LINECOUNTER+1
> done < "$SAPATH/sa01"
>
> ./sarcpu2
>
> ./sar_cpu2: let: AVG[4]=100-/2: syntax error: operand expected (error
> token is "/2")
This all is a bit much. But SUM[4] seems to not be initialized in the
line marked as '!!!!!', and the backticks in the line marked '?????'
seems just wrong to me.
Janis
Re: Script error
am 07.12.2007 00:15:52 von apogeusistemas
On 6 dez, 20:15, Janis Papanagnou
wrote:
> apogeusiste...@gmail.com wrote:
> > Hi:
>
> > Can You tell me why this script works fine in Solaris10, but when I
> > transfer this script to
> > a Solaris 8 machine I get errors ?
>
> > # cat sar_cpu2
> > #!/bin/bash
> > set -x
> > clear
> > echo
>
> > LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
> > 23 24 25 26 27 28 29 30 31"
>
> > echo "Entre com os sabados, domingos e feriados a serem excluidos -
> > separados por espaco: "; read weekend_days
> > lav=`/usr/xpg4/bin/grep -vf <(echo $weekend_days | tr ' ' '\n') <(echo
> > $LA |tr ' ' '\n')`
> > echo " Entre com o endereco do arquivos sar binarios: " ; read
> > endereco
> > dias=`echo $lav | awk '{ print NF }'`
> > #echo $lav
> > #echo $endereco
> > #echo $dias
>
> > LINECOUNTER="1"
> > SAPATH="/tmp" # dir of your sa-files
> > SUM=(0,0,0,0)
> > DAYS="$dias" # number of days
> > HUNDRED="100"
>
> > rm /tmp/sa??
>
> > for I in $lav
> > do
> > #echo $I
> > sar -u -f $endereco/sa$I > /tmp/sa$I
> > #ls /tmp/sa??
> > done
> > while read FOO
> > do
> > SUM=(0,0,0,0)
>
> > for I in $lav
> > do
> > ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
>
> > case "${ELEMENT[1]}" in
> > [0-9]*)
> > let SUM[1]=${SUM[1]}=0
> > let SUM[2]=${SUM[2]}=0
> > let SUM[3]=${SUM[3]}=0
> > let SUM[4]=`${SUM[4]}`+${ELEMENT[4]}
>
> ?????
>
> > ;;
> > *)
> > NEWLINE="${ELEMENT[@]}"
> > ;;
> > esac
> > done
>
> > case ${ELEMENT[1]} in
> > [0-9]*)
> > let AVG[1]=0
> > let AVG[2]=0
> > let AVG[3]=0
> > ## let AVG[4]=${SUM[4]}/$DAYS
> > let AVG[4]=$HUNDRED-${SUM[4]}/$DAYS
>
> !!!!!
>
>
>
>
>
>
>
> > ## echo "${ELEMENT[0]} ${AVG[1]} ${AVG[2]} $
> > {AVG[3]} ${AVG[4]}"
>
> > ## printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} $
> > {AVG[1]} ${AVG[2]} ${AVG[3]} ${AVG[4]}
> > printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} ${AVG[4]} $
> > {AVG[2]} ${AVG[3]} ${AVG[1]}
> > ;;
> > *)
> > echo "$NEWLINE"
> > ;;
> > esac
>
> > let LINECOUNTER=LINECOUNTER+1
> > done < "$SAPATH/sa01"
>
> > ./sarcpu2
>
> > ./sar_cpu2: let: AVG[4]=100-/2: syntax error: operand expected (error
> > token is "/2")
>
> This all is a bit much. But SUM[4] seems to not be initialized in the
> line marked as '!!!!!', and the backticks in the line marked '?????'
> seems just wrong to me.
>
> Janis- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -
Sorry, trying fix I put a ` ` , but this is the right script:
#!/bin/bash
set -x
clear
echo
LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24 25 26 27 28 29 30 31"
echo "Entre com os sabados, domingos e feriados a serem excluidos -
separados por espaco: "; read weekend_days
lav=`/usr/xpg4/bin/grep -vf <(echo $weekend_days | tr ' ' '\n') <(echo
$LA |tr ' ' '\n')`
echo " Entre com o endereco do arquivos sar binarios: " ; read
endereco
dias=`echo $lav | awk '{ print NF }'`
#echo $lav
#echo $endereco
#echo $dias
LINECOUNTER="1"
SAPATH="/tmp" # dir of your sa-files
SUM=(0,0,0,0)
DAYS="$dias" # number of days
HUNDRED="100"
rm /tmp/sa??
for I in $lav
do
#echo $I
sar -u -f $endereco/sa$I > /tmp/sa$I
#ls /tmp/sa??
done
while read FOO
do
SUM=(0,0,0,0)
for I in $lav
do
ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
case "${ELEMENT[1]}" in
[0-9]*)
let SUM[1]=${SUM[1]}=0
let SUM[2]=${SUM[2]}=0
let SUM[3]=${SUM[3]}=0
let SUM[4]=${SUM[4]}+${ELEMENT[4]}
;;
*)
NEWLINE="${ELEMENT[@]}"
;;
esac
done
case ${ELEMENT[1]} in
[0-9]*)
let AVG[1]=0
let AVG[2]=0
let AVG[3]=0
## let AVG[4]=${SUM[4]}/$DAYS
let AVG[4]=$HUNDRED-${SUM[4]}/$DAYS
## echo "${ELEMENT[0]} ${AVG[1]} ${AVG[2]} $
{AVG[3]} ${AVG[4]}"
## printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} $
{AVG[1]} ${AVG[2]} ${AVG[3]} ${AVG[4]}
printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} ${AVG[4]} $
{AVG[2]} ${AVG[3]} ${AVG[1]}
;;
*)
echo "$NEWLINE"
;;
esac
let LINECOUNTER=LINECOUNTER+1
done < "$SAPATH/sa01"
../sar_cpu2
# ./sar_cpu2
+ clear
+ echo
+ LA=01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24 25 26 27 28 29 30 31
+ echo 'Entre com os sabados, domingos e feriados a serem excluidos -
separados por espaco: '
Entre com os sabados, domingos e feriados a serem excluidos -
separados por espaco:
+ read weekend_days
02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31
++ /usr/xpg4/bin/grep -vf /dev/fd/63 /dev/fd/62
+++ echo 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21
22 23 24 25 26 27 28 29 30 31
+++ tr ' ' '\n'
+++ echo 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31
+++ tr ' ' '\n'
+ lav=01
+ echo ' Entre com o endereco do arquivos sar binarios: '
Entre com o endereco do arquivos sar binarios:
+ read endereco
/var/adm/sa
++ echo 01
++ awk '{ print NF }'
+ dias=1
+ LINECOUNTER=1
+ SAPATH=/tmp
+ SUM=(0,0,0,0)
+ DAYS=1
+ HUNDRED=100
+ rm /tmp/sa01 /tmp/sa02
+ sar -u -f /var/adm/sa/sa01
+ read FOO
+ SUM=(0,0,0,0)
+ ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
++ head -n 1 /tmp/sa01
++ tail -1
+ NEWLINE=
+ echo ''
+ let LINECOUNTER=LINECOUNTER+1
+ read FOO
+ SUM=(0,0,0,0)
+ ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
++ head -n 2 /tmp/sa01
++ tail -1
+ NEWLINE=SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07
+ echo 'SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07'
SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07
+ let LINECOUNTER=LINECOUNTER+1
+ read FOO
+ SUM=(0,0,0,0)
+ ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
++ head -n 3 /tmp/sa01
++ tail -1
+ NEWLINE=
+ echo ''
+ let LINECOUNTER=LINECOUNTER+1
+ read FOO
+ SUM=(0,0,0,0)
+ ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
++ head -n 4 /tmp/sa01
++ tail -1
+ NEWLINE=00:00:00 %usr %sys %wio %idle
+ echo '00:00:00 %usr %sys %wio %idle'
00:00:00 %usr %sys %wio %idle
+ let LINECOUNTER=LINECOUNTER+1
+ read FOO
+ SUM=(0,0,0,0)
+ ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
++ head -n 5 /tmp/sa01
++ tail -1
+ let 'SUM[1]==0'
+ let 'SUM[2]==0'
+ let 'SUM[3]==0'
+ let 'SUM[4]=+38'
+ let 'AVG[1]=0'
+ let 'AVG[2]=0'
+ let 'AVG[3]=0'
+ let 'AVG[4]=100-/1'
../sar_cpu2: let: AVG[4]=100-/1: syntax error: operand expected (error
token is "/1")
Re: Script error
am 07.12.2007 01:13:38 von Janis Papanagnou
apogeusistemas@gmail.com wrote:
> On 6 dez, 20:15, Janis Papanagnou
> wrote:
>
>>apogeusiste...@gmail.com wrote:
>>
>>>[snip]
>>
>>This all is a bit much. But SUM[4] seems to not be initialized in the
>>line marked as '!!!!!', and the backticks in the line marked '?????'
>>seems just wrong to me.
>>
>>Janis- Ocultar texto entre aspas -
>>
>>- Mostrar texto entre aspas -- Ocultar texto entre aspas -
>>
>>- Mostrar texto entre aspas -
>
>
> Sorry, trying fix I put a ` ` , but this is the right script:
>
>
> #!/bin/bash
> set -x
> clear
> echo
>
> LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
> 23 24 25 26 27 28 29 30 31"
>
> echo "Entre com os sabados, domingos e feriados a serem excluidos -
> separados por espaco: "; read weekend_days
> lav=`/usr/xpg4/bin/grep -vf <(echo $weekend_days | tr ' ' '\n') <(echo
> $LA |tr ' ' '\n')`
> echo " Entre com o endereco do arquivos sar binarios: " ; read
> endereco
> dias=`echo $lav | awk '{ print NF }'`
> #echo $lav
> #echo $endereco
> #echo $dias
>
> LINECOUNTER="1"
> SAPATH="/tmp" # dir of your sa-files
> SUM=(0,0,0,0)
I think you mean...
SUM=( 0 0 0 0 )
At least in Kornshell you need that syntax; off top of my head I'm
not aware of any specific bash syntax.
> DAYS="$dias" # number of days
> HUNDRED="100"
>
> rm /tmp/sa??
>
> for I in $lav
> do
> #echo $I
> sar -u -f $endereco/sa$I > /tmp/sa$I
> #ls /tmp/sa??
> done
> while read FOO
> do
> SUM=(0,0,0,0)
As above.
>
> for I in $lav
> do
> ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
>
> case "${ELEMENT[1]}" in
> [0-9]*)
> let SUM[1]=${SUM[1]}=0
> let SUM[2]=${SUM[2]}=0
> let SUM[3]=${SUM[3]}=0
Are the above three lines intentional defined that way?
And also be aware that arrays are indexed starting by 0, so you'll
have SUM[0]..SUM[3] defined but not SUM[4].
Generally I'd avoid the 'let' command; I'd use $(( ... )) instead.
Another general suggestion is to print out variables at certain places
where the values seem to be calculated wrong.
Janis
> let SUM[4]=${SUM[4]}+${ELEMENT[4]}
> ;;
> *)
> NEWLINE="${ELEMENT[@]}"
> ;;
> esac
> done
>
>
> case ${ELEMENT[1]} in
> [0-9]*)
> let AVG[1]=0
> let AVG[2]=0
> let AVG[3]=0
> ## let AVG[4]=${SUM[4]}/$DAYS
> let AVG[4]=$HUNDRED-${SUM[4]}/$DAYS
>
>
> ## echo "${ELEMENT[0]} ${AVG[1]} ${AVG[2]} $
> {AVG[3]} ${AVG[4]}"
>
> ## printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} $
> {AVG[1]} ${AVG[2]} ${AVG[3]} ${AVG[4]}
> printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} ${AVG[4]} $
> {AVG[2]} ${AVG[3]} ${AVG[1]}
> ;;
> *)
> echo "$NEWLINE"
> ;;
> esac
>
>
> let LINECOUNTER=LINECOUNTER+1
> done < "$SAPATH/sa01"
>
>
>
> ./sar_cpu2
>
> # ./sar_cpu2
> + clear
>
> + echo
>
> + LA=01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
> 23 24 25 26 27 28 29 30 31
> + echo 'Entre com os sabados, domingos e feriados a serem excluidos -
> separados por espaco: '
> Entre com os sabados, domingos e feriados a serem excluidos -
> separados por espaco:
> + read weekend_days
> 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
> 25 26 27 28 29 30 31
> ++ /usr/xpg4/bin/grep -vf /dev/fd/63 /dev/fd/62
> +++ echo 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21
> 22 23 24 25 26 27 28 29 30 31
> +++ tr ' ' '\n'
> +++ echo 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
> 21 22 23 24 25 26 27 28 29 30 31
> +++ tr ' ' '\n'
> + lav=01
> + echo ' Entre com o endereco do arquivos sar binarios: '
> Entre com o endereco do arquivos sar binarios:
> + read endereco
> /var/adm/sa
> ++ echo 01
> ++ awk '{ print NF }'
> + dias=1
> + LINECOUNTER=1
> + SAPATH=/tmp
> + SUM=(0,0,0,0)
> + DAYS=1
> + HUNDRED=100
> + rm /tmp/sa01 /tmp/sa02
> + sar -u -f /var/adm/sa/sa01
> + read FOO
> + SUM=(0,0,0,0)
> + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
> ++ head -n 1 /tmp/sa01
> ++ tail -1
> + NEWLINE=
> + echo ''
>
> + let LINECOUNTER=LINECOUNTER+1
> + read FOO
> + SUM=(0,0,0,0)
> + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
> ++ head -n 2 /tmp/sa01
> ++ tail -1
> + NEWLINE=SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07
> + echo 'SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07'
> SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07
> + let LINECOUNTER=LINECOUNTER+1
> + read FOO
> + SUM=(0,0,0,0)
> + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
> ++ head -n 3 /tmp/sa01
> ++ tail -1
> + NEWLINE=
> + echo ''
>
> + let LINECOUNTER=LINECOUNTER+1
> + read FOO
> + SUM=(0,0,0,0)
> + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
> ++ head -n 4 /tmp/sa01
> ++ tail -1
> + NEWLINE=00:00:00 %usr %sys %wio %idle
> + echo '00:00:00 %usr %sys %wio %idle'
> 00:00:00 %usr %sys %wio %idle
> + let LINECOUNTER=LINECOUNTER+1
> + read FOO
> + SUM=(0,0,0,0)
> + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
> ++ head -n 5 /tmp/sa01
> ++ tail -1
> + let 'SUM[1]==0'
> + let 'SUM[2]==0'
> + let 'SUM[3]==0'
> + let 'SUM[4]=+38'
> + let 'AVG[1]=0'
> + let 'AVG[2]=0'
> + let 'AVG[3]=0'
> + let 'AVG[4]=100-/1'
> ./sar_cpu2: let: AVG[4]=100-/1: syntax error: operand expected (error
> token is "/1")
Re: Script error
am 07.12.2007 01:39:35 von apogeusistemas
On 6 dez, 22:13, Janis Papanagnou
wrote:
> apogeusiste...@gmail.com wrote:
> > On 6 dez, 20:15, Janis Papanagnou
> > wrote:
>
> >>apogeusiste...@gmail.com wrote:
>
> >>>[snip]
>
> >>This all is a bit much. But SUM[4] seems to not be initialized in the
> >>line marked as '!!!!!', and the backticks in the line marked '?????'
> >>seems just wrong to me.
>
> >>Janis- Ocultar texto entre aspas -
>
> >>- Mostrar texto entre aspas -- Ocultar texto entre aspas -
>
> >>- Mostrar texto entre aspas -
>
> > Sorry, trying fix I put a ` ` , but this is the right script:
>
> > #!/bin/bash
> > set -x
> > clear
> > echo
>
> > LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
> > 23 24 25 26 27 28 29 30 31"
>
> > echo "Entre com os sabados, domingos e feriados a serem excluidos -
> > separados por espaco: "; read weekend_days
> > lav=`/usr/xpg4/bin/grep -vf <(echo $weekend_days | tr ' ' '\n') <(echo
> > $LA |tr ' ' '\n')`
> > echo " Entre com o endereco do arquivos sar binarios: " ; read
> > endereco
> > dias=`echo $lav | awk '{ print NF }'`
> > #echo $lav
> > #echo $endereco
> > #echo $dias
>
> > LINECOUNTER="1"
> > SAPATH="/tmp" # dir of your sa-files
> > SUM=(0,0,0,0)
>
> I think you mean...
>
> SUM=( 0 0 0 0 )
>
> At least in Kornshell you need that syntax; off top of my head I'm
> not aware of any specific bash syntax.
>
> > DAYS="$dias" # number of days
> > HUNDRED="100"
>
> > rm /tmp/sa??
>
> > for I in $lav
> > do
> > #echo $I
> > sar -u -f $endereco/sa$I > /tmp/sa$I
> > #ls /tmp/sa??
> > done
> > while read FOO
> > do
> > SUM=(0,0,0,0)
>
> As above.
>
>
>
> > for I in $lav
> > do
> > ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
>
> > case "${ELEMENT[1]}" in
> > [0-9]*)
> > let SUM[1]=${SUM[1]}=0
> > let SUM[2]=${SUM[2]}=0
> > let SUM[3]=${SUM[3]}=0
>
> Are the above three lines intentional defined that way?
>
> And also be aware that arrays are indexed starting by 0, so you'll
> have SUM[0]..SUM[3] defined but not SUM[4].
>
> Generally I'd avoid the 'let' command; I'd use $(( ... )) instead.
>
> Another general suggestion is to print out variables at certain places
> where the values seem to be calculated wrong.
>
> Janis
>
>
>
> > let SUM[4]=${SUM[4]}+${ELEMENT[4]}
> > ;;
> > *)
> > NEWLINE="${ELEMENT[@]}"
> > ;;
> > esac
> > done
>
> > case ${ELEMENT[1]} in
> > [0-9]*)
> > let AVG[1]=0
> > let AVG[2]=0
> > let AVG[3]=0
> > ## let AVG[4]=${SUM[4]}/$DAYS
> > let AVG[4]=$HUNDRED-${SUM[4]}/$DAYS
>
> > ## echo "${ELEMENT[0]} ${AVG[1]} ${AVG[2]} $
> > {AVG[3]} ${AVG[4]}"
>
> > ## printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} $
> > {AVG[1]} ${AVG[2]} ${AVG[3]} ${AVG[4]}
> > printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} ${AVG[4]} $
> > {AVG[2]} ${AVG[3]} ${AVG[1]}
> > ;;
> > *)
> > echo "$NEWLINE"
> > ;;
> > esac
>
> > let LINECOUNTER=LINECOUNTER+1
> > done < "$SAPATH/sa01"
>
> > ./sar_cpu2
>
> > # ./sar_cpu2
> > + clear
>
> > + echo
>
> > + LA=01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
> > 23 24 25 26 27 28 29 30 31
> > + echo 'Entre com os sabados, domingos e feriados a serem excluidos -
> > separados por espaco: '
> > Entre com os sabados, domingos e feriados a serem excluidos -
> > separados por espaco:
> > + read weekend_days
> > 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
> > 25 26 27 28 29 30 31
> > ++ /usr/xpg4/bin/grep -vf /dev/fd/63 /dev/fd/62
> > +++ echo 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21
> > 22 23 24 25 26 27 28 29 30 31
> > +++ tr ' ' '\n'
> > +++ echo 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
> > 21 22 23 24 25 26 27 28 29 30 31
> > +++ tr ' ' '\n'
> > + lav=01
> > + echo ' Entre com o endereco do arquivos sar binarios: '
> > Entre com o endereco do arquivos sar binarios:
> > + read endereco
> > /var/adm/sa
> > ++ echo 01
> > ++ awk '{ print NF }'
> > + dias=1
> > + LINECOUNTER=1
> > + SAPATH=/tmp
> > + SUM=(0,0,0,0)
> > + DAYS=1
> > + HUNDRED=100
> > + rm /tmp/sa01 /tmp/sa02
> > + sar -u -f /var/adm/sa/sa01
> > + read FOO
> > + SUM=(0,0,0,0)
> > + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
> > ++ head -n 1 /tmp/sa01
> > ++ tail -1
> > + NEWLINE=
> > + echo ''
>
> > + let LINECOUNTER=LINECOUNTER+1
> > + read FOO
> > + SUM=(0,0,0,0)
> > + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
> > ++ head -n 2 /tmp/sa01
> > ++ tail -1
> > + NEWLINE=SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07
> > + echo 'SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07'
> > SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07
> > + let LINECOUNTER=LINECOUNTER+1
> > + read FOO
> > + SUM=(0,0,0,0)
> > + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
> > ++ head -n 3 /tmp/sa01
> > ++ tail -1
> > + NEWLINE=
> > + echo ''
>
> > + let LINECOUNTER=LINECOUNTER+1
> > + read FOO
> > + SUM=(0,0,0,0)
> > + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
> > ++ head -n 4 /tmp/sa01
> > ++ tail -1
> > + NEWLINE=00:00:00 %usr %sys %wio %idle
> > + echo '00:00:00 %usr %sys %wio %idle'
> > 00:00:00 %usr %sys %wio %idle
> > + let LINECOUNTER=LINECOUNTER+1
> > + read FOO
> > + SUM=(0,0,0,0)
> > + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
> > ++ head -n 5 /tmp/sa01
> > ++ tail -1
> > + let 'SUM[1]==0'
> > + let 'SUM[2]==0'
> > + let 'SUM[3]==0'
> > + let 'SUM[4]=+38'
> > + let 'AVG[1]=0'
> > + let 'AVG[2]=0'
> > + let 'AVG[3]=0'
> > + let 'AVG[4]=100-/1'
> > ./sar_cpu2: let: AVG[4]=100-/1: syntax error: operand expected (error
> > token is "/1")- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -
I cannot undestand why this error only happens in solaris 8...
In solaris 10 it works fine...
../sar_cpu2: let: AVG[4]=100-/1: syntax error: operand expected (error
token is "/1")
Re: Script error
am 07.12.2007 01:56:03 von Janis Papanagnou
apogeusistemas@gmail.com wrote:
>
> [big snip]
>
> I cannot undestand why this error only happens in solaris 8...
> In solaris 10 it works fine...
If your program is wrong it may produce so called "undefined results";
which can differ in different system environments.
Try fixing the errors.
>
>
> ./sar_cpu2: let: AVG[4]=100-/1: syntax error: operand expected (error
> token is "/1")
I assume you are aware, meanwhile, that you seem to be expanding then
undefined variable SUM[4].
Janis
Re: Script error
am 07.12.2007 06:21:05 von Cyrus Kriticos
apogeusistemas@gmail.com wrote:
> On 6 dez, 22:13, Janis Papanagnou
> wrote:
>> apogeusiste...@gmail.com wrote:
>>> On 6 dez, 20:15, Janis Papanagnou
>>> wrote:
>>>> apogeusiste...@gmail.com wrote:
>>>>> [snip]
>>>> This all is a bit much. But SUM[4] seems to not be initialized in the
>>>> line marked as '!!!!!', and the backticks in the line marked '?????'
>>>> seems just wrong to me.
>>>> Janis- Ocultar texto entre aspas -
>>>> - Mostrar texto entre aspas -- Ocultar texto entre aspas -
>>>> - Mostrar texto entre aspas -
>>> Sorry, trying fix I put a ` ` , but this is the right script:
>>> #!/bin/bash
>>> set -x
>>> clear
>>> echo
>>> LA="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
>>> 23 24 25 26 27 28 29 30 31"
>>> echo "Entre com os sabados, domingos e feriados a serem excluidos -
>>> separados por espaco: "; read weekend_days
>>> lav=`/usr/xpg4/bin/grep -vf <(echo $weekend_days | tr ' ' '\n') <(echo
>>> $LA |tr ' ' '\n')`
>>> echo " Entre com o endereco do arquivos sar binarios: " ; read
>>> endereco
>>> dias=`echo $lav | awk '{ print NF }'`
>>> #echo $lav
>>> #echo $endereco
>>> #echo $dias
>>> LINECOUNTER="1"
>>> SAPATH="/tmp" # dir of your sa-files
>>> SUM=(0,0,0,0)
>> I think you mean...
>>
>> SUM=( 0 0 0 0 )
>>
>> At least in Kornshell you need that syntax; off top of my head I'm
>> not aware of any specific bash syntax.
>>
>>> DAYS="$dias" # number of days
>>> HUNDRED="100"
>>> rm /tmp/sa??
>>> for I in $lav
>>> do
>>> #echo $I
>>> sar -u -f $endereco/sa$I > /tmp/sa$I
>>> #ls /tmp/sa??
>>> done
>>> while read FOO
>>> do
>>> SUM=(0,0,0,0)
>> As above.
>>
>>
>>
>>> for I in $lav
>>> do
>>> ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
>>> case "${ELEMENT[1]}" in
>>> [0-9]*)
>>> let SUM[1]=${SUM[1]}=0
>>> let SUM[2]=${SUM[2]}=0
>>> let SUM[3]=${SUM[3]}=0
>> Are the above three lines intentional defined that way?
>>
>> And also be aware that arrays are indexed starting by 0, so you'll
>> have SUM[0]..SUM[3] defined but not SUM[4].
>>
>> Generally I'd avoid the 'let' command; I'd use $(( ... )) instead.
>>
>> Another general suggestion is to print out variables at certain places
>> where the values seem to be calculated wrong.
>>
>> Janis
>>
>>
>>
>>> let SUM[4]=${SUM[4]}+${ELEMENT[4]}
>>> ;;
>>> *)
>>> NEWLINE="${ELEMENT[@]}"
>>> ;;
>>> esac
>>> done
>>> case ${ELEMENT[1]} in
>>> [0-9]*)
>>> let AVG[1]=0
>>> let AVG[2]=0
>>> let AVG[3]=0
>>> ## let AVG[4]=${SUM[4]}/$DAYS
>>> let AVG[4]=$HUNDRED-${SUM[4]}/$DAYS
>>> ## echo "${ELEMENT[0]} ${AVG[1]} ${AVG[2]} $
>>> {AVG[3]} ${AVG[4]}"
>>> ## printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} $
>>> {AVG[1]} ${AVG[2]} ${AVG[3]} ${AVG[4]}
>>> printf "%-8s %7d %7d %7d %7d\n" ${ELEMENT[0]} ${AVG[4]} $
>>> {AVG[2]} ${AVG[3]} ${AVG[1]}
>>> ;;
>>> *)
>>> echo "$NEWLINE"
>>> ;;
>>> esac
>>> let LINECOUNTER=LINECOUNTER+1
>>> done < "$SAPATH/sa01"
>>> ./sar_cpu2
>>> # ./sar_cpu2
>>> + clear
>>> + echo
>>> + LA=01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
>>> 23 24 25 26 27 28 29 30 31
>>> + echo 'Entre com os sabados, domingos e feriados a serem excluidos -
>>> separados por espaco: '
>>> Entre com os sabados, domingos e feriados a serem excluidos -
>>> separados por espaco:
>>> + read weekend_days
>>> 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
>>> 25 26 27 28 29 30 31
>>> ++ /usr/xpg4/bin/grep -vf /dev/fd/63 /dev/fd/62
>>> +++ echo 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21
>>> 22 23 24 25 26 27 28 29 30 31
>>> +++ tr ' ' '\n'
>>> +++ echo 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
>>> 21 22 23 24 25 26 27 28 29 30 31
>>> +++ tr ' ' '\n'
>>> + lav=01
>>> + echo ' Entre com o endereco do arquivos sar binarios: '
>>> Entre com o endereco do arquivos sar binarios:
>>> + read endereco
>>> /var/adm/sa
>>> ++ echo 01
>>> ++ awk '{ print NF }'
>>> + dias=1
>>> + LINECOUNTER=1
>>> + SAPATH=/tmp
>>> + SUM=(0,0,0,0)
>>> + DAYS=1
>>> + HUNDRED=100
>>> + rm /tmp/sa01 /tmp/sa02
>>> + sar -u -f /var/adm/sa/sa01
>>> + read FOO
>>> + SUM=(0,0,0,0)
>>> + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
>>> ++ head -n 1 /tmp/sa01
>>> ++ tail -1
>>> + NEWLINE=
>>> + echo ''
>>> + let LINECOUNTER=LINECOUNTER+1
>>> + read FOO
>>> + SUM=(0,0,0,0)
>>> + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
>>> ++ head -n 2 /tmp/sa01
>>> ++ tail -1
>>> + NEWLINE=SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07
>>> + echo 'SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07'
>>> SunOS ugmtzsux005 5.8 Generic_117350-02 sun4u 12/01/07
>>> + let LINECOUNTER=LINECOUNTER+1
>>> + read FOO
>>> + SUM=(0,0,0,0)
>>> + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
>>> ++ head -n 3 /tmp/sa01
>>> ++ tail -1
>>> + NEWLINE=
>>> + echo ''
>>> + let LINECOUNTER=LINECOUNTER+1
>>> + read FOO
>>> + SUM=(0,0,0,0)
>>> + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
>>> ++ head -n 4 /tmp/sa01
>>> ++ tail -1
>>> + NEWLINE=00:00:00 %usr %sys %wio %idle
>>> + echo '00:00:00 %usr %sys %wio %idle'
>>> 00:00:00 %usr %sys %wio %idle
>>> + let LINECOUNTER=LINECOUNTER+1
>>> + read FOO
>>> + SUM=(0,0,0,0)
>>> + ELEMENT=($(head -n $LINECOUNTER $SAPATH/sa$I | tail -1))
>>> ++ head -n 5 /tmp/sa01
>>> ++ tail -1
>>> + let 'SUM[1]==0'
>>> + let 'SUM[2]==0'
>>> + let 'SUM[3]==0'
>>> + let 'SUM[4]=+38'
>>> + let 'AVG[1]=0'
>>> + let 'AVG[2]=0'
>>> + let 'AVG[3]=0'
>>> + let 'AVG[4]=100-/1'
>>> ./sar_cpu2: let: AVG[4]=100-/1: syntax error: operand expected (error
>>> token is "/1")- Ocultar texto entre aspas -
>> - Mostrar texto entre aspas -- Ocultar texto entre aspas -
>>
>> - Mostrar texto entre aspas -
>
>
> I cannot undestand why this error only happens in solaris 8...
> In solaris 10 it works fine...
It's an error in my example I posted a few days ago. Janis is right, you
should start arrays with index 0.
This error perhaps appears in Solaris 8 and not in Solaris 10 because of a
different versions of bash.
> ./sar_cpu2: let: AVG[4]=100-/1: syntax error: operand expected (error
> token is "/1")
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.