mercredi 22 février 2017

Why do I get an extra 0 on my script

I don't know why I get an extra 0 when I run my script.

This is my script: I run a SQL query and save it ta an file valor.txt.

This is my array: array=(50 60 70)

Valor.txt:

 count | trn_hst_id | trn_msg_host
-------+------------+--------------
    11 |         50 | Aprobada
     2 |         70 | Aprobada
(2 rows)

Code:

function service_status {
    cd
    cat valor.txt | grep $1 | gawk '{print $1}' FS="|" | sed "s/ //g"
    if [ $? -eq 0 ]; then
        echo -n 0
        else
        echo -n $1
    fi
}

        echo "<prtg>"

# <-- Start
        for i in "${array[@]}"
        do

        echo -n "   <result>
       <channel>$i</channel>
       <value>"
        service_status $i
        echo "</value>
       </result>"
       done
# End -->
       echo "</prtg>"
       exit

And this is my output.

<prtg>
   <result>
       <channel>50</channel>
       <value>11
0</value>
       </result>
   <result>
       <channel>60</channel>
       <value>0</value>
       </result>
   <result>
       <channel>70</channel>
       <value>2
0</value>
       </result>
</prtg>

Why do I get the 0 here? —

       <value>2
0</value>

Aucun commentaire:

Enregistrer un commentaire