你好,你可以试试我这个:
sec=300
while [ 1 ]
do
killall tcpdump
mv ip.packet ip.packet.1
tcpdump -w ip.packet -s 0 tcp or udp &
rrd_data=""
traffic=`tcpdump -r ip.packet.1 src 192.168.0.1 and dst 192.168.0.2 -v | sed -e 's/.*, length: \(.*\))/\1/g' | awk -F " " '{print $1}'| sed -e 's/)//g'| tr '\n' '+'`
traffic=`echo ${traffic}0 | bc`
traffic=`expr $traffic / $sec`
rrd_data=$traffic
echo $rrd_data >1.txt
echo $rrd_data >>2.txt
sleep $sec
done
你可以试试这个:
sec=300
while [ 1 ]
do
killall tcpdump
mv ip.packet ip.packet.1
tcpdump -w ip.packet -s 0 tcp or udp &
rrd_data=""
traffic=`tcpdump -r ip.packet.1 src 192.168.0.1 and dst 192.168.0.2 -v | sed -e 's/.*, length: \(.*\))/\1/g' | awk -F " " '{print $1}'| sed -e 's/)//g'| tr '\n' '+'`
traffic=`echo ${traffic}0 | bc`
traffic=`expr $traffic / $sec`
rrd_data=$traffic
echo $rrd_data >1.txt
echo $rrd_data >>2.txt
sleep $sec
done