PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : pls help bei bash scripting


(del676)
2004-02-26, 10:55:08
moin
ich würd gern ein bash script schreiben das die durchschnittspunkte unserer spammails auswirft - soweit bin ich schon:


#/bin/bash
z=0
spamcount=`tail -n 500 /var/log/mail.info | grep identified | sed -e 's/^.*(//' -e 's/\/.*$//' | wc -l`
echo spammails $spamcount
export z

tail -n 500 /var/log/mail.info | grep identified | sed -e 's/^.*(//' -e 's/\/.*$//' | while read line
do
z=`echo $z + $line | bc -l`
echo loop $z
done

echo end $z


jetzt hab ich das problem das in der while loop die variable z richtig is, aber am ende (beim letzten echo $z ausserhalb der schleife) will der mir weiss machen das z=0 is - warum auch immer

weiss da einer rat?
(habs auch schon mit declare versucht - kein erfolg)

raus kommt in etwa das:
u015 root # spamcalc
spammails 5
loop 6.5
loop 19.7
loop 27.7
loop 37.1
loop 65.4
end 0

(del676)
2004-02-26, 11:35:28
ah habs gaylöst :)

tail -n 500 /var/log/mail.info | grep identified | sed -e 's/^.*(//' -e 's/\/.*$//' | while read line

das reisst mir einen subprozess auf, und wenn der beendet wird is natürlich Z wieder weg :)

deshalb



tail -n 2000 /var/log/mail.info | grep identified | sed -e 's/^.*(//' -e 's/\/.*$//' > /tmp/spamcalc.tmp
while read line
do
z=`echo $z + $line | bc -l`
echo loop $z
done < /tmp/spamcalc.tmp