Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- let n=0
- while true
- do
- let tx_bytes=0
- let tx_bytes_nuevos=0
- let tx_bytes_actuales=0
- trafico_in=""
- total_in=""
- let rx_bytes=0
- let rx_bytes_nuevos=0
- let rx_bytes_actuales=0
- trafico_out=""
- total_out=""
- if [ -f /tmp/tx_bytes ]
- then
- sudo rm /tmp/tx_bytes
- elif [ -f /tmp/rx_bytes ]
- then
- sudo rm /tmp/rx_bytes
- fi
- sudo iptables -L INPUT -n -v -x > /tmp/tx_bytes
- sudo sed -i '1,2d' /tmp/tx_bytes
- sudo sed -i 's/^ *//g' /tmp/tx_bytes
- sudo sed -i 's/ */;/g' /tmp/tx_bytes
- sudo iptables -L OUTPUT -n -v -x > /tmp/rx_bytes
- sudo sed -i '1,2d' /tmp/rx_bytes
- sudo sed -i 's/^ *//g' /tmp/rx_bytes
- sudo sed -i 's/ */;/g' /tmp/rx_bytes
- while read line
- do
- line=`echo $line | cut -d";" -f2`
- tx_bytes=$line
- let tx_bytes_actuales+=$tx_bytes
- done < /tmp/tx_bytes
- if [ $tx_bytes_actuales -lt 1024 ]
- then
- total_in=$tx_bytes_actuales
- bajado_total=`echo "$total_in B"`
- fi
- if [[ $tx_bytes_actuales -ge 1024 && $tx_bytes_actuales -lt 1048576 ]]
- then
- total_in=`echo "scale=2; $tx_bytes_actuales/1024" | bc`
- bajado_total=`echo "$total_in Kb"`
- fi
- if [ $tx_bytes_actuales -ge 1048576 ]
- then
- total_in=`echo "scale=2; $tx_bytes_actuales/1048576" | bc`
- bajado_total=`echo "$total_in Mb"`
- fi
- if [ $n -eq 0 ]
- then
- tx_bytes_anteriores=$tx_bytes_actuales
- fi
- let tx_bytes_nuevos=$tx_bytes_actuales-$tx_bytes_anteriores
- tx_bytes_anteriores=$tx_bytes_actuales
- trafico_in=`echo "scale=2; $tx_bytes_nuevos/1024" | bc`
- trafico_in=`echo "scale=2; $trafico_in/(11/2)" | bc`
- entrando=`echo "$trafico_in Kb/s"`
- while read line
- do
- line=`echo $line | cut -d";" -f2`
- rx_bytes=$line
- let rx_bytes_actuales+=$rx_bytes
- done < /tmp/rx_bytes
- if [ $rx_bytes_actuales -lt 1024 ]
- then
- total_out=$rx_bytes_actuales
- subido_total=`echo "$total_out B"`
- fi
- if [[ $rx_bytes_actuales -ge 1024 && $rx_bytes_actuales -lt 1048576 ]]
- then
- total_out=`echo "scale=2; $rx_bytes_actuales/1024" | bc`
- subido_total=`echo "$total_out Kb"`
- fi
- if [ $rx_bytes_actuales -ge 1048576 ]
- then
- total_out=`echo "scale=2; $rx_bytes_actuales/1048576" | bc`
- subido_total=`echo "$total_out Mb"`
- fi
- if [ $n -eq 0 ]
- then
- rx_bytes_anteriores=$rx_bytes_actuales
- fi
- let rx_bytes_nuevos=$rx_bytes_actuales-$rx_bytes_anteriores
- rx_bytes_anteriores=$rx_bytes_actuales
- trafico_out=`echo "scale=2; $rx_bytes_nuevos/1024" | bc`
- trafico_out=`echo "scale=2; $trafico_out/(11/2)" | bc`
- saliendo=`echo "$trafico_out Kb/s"`
- if [ -f /tmp/tx_rx_bytes ]
- then
- sed -i '1d' /tmp/tx_rx_bytes
- echo "$bajado_total:$entrando:$subido_total:$saliendo" > /tmp/tx_rx_bytes
- else
- echo "$bajado_total:$entrando:$subido_total:$saliendo" > /tmp/tx_rx_bytes
- fi
- let n=$n+1
- sleep 5
- done
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement