В коде использован bar:
http://www.theiling.de/projects/bar.html
#! /bin/bash # dig in dump # writen by Sanych ##### version="3.4.1 от Tue Jul 15 14:24:53 MSD 2008" # variables year=`date +%Y` green="\033[01;32m" black="\033[00m" redy="\033[01;31m" # check CTRL-C trap 'sudo rm -f /var/log/dump/nachalo${userl}$$ /var/log/dump/konec${userl}$$ ; exit 1' 2 # not for root if [ $USER == "root" ] ; then if [ -z $SUDO_USER ] ; then echo -e "${redy}Not for root, please use sudo -u user `basename $0`${black}" exit 255 else userl=$SUDO_USER fi else userl=$USER fi # usage if [ $# -lt 3 ] ; then echo "Логирование клиента ver $version" echo "Использование: `basename $0` DD-MM[-YEAR](от какой даты) DD-MM[-YEAR](по какую дату) IPADDR [nosend]" echo -e "лог-файл отправляется на ${green}support@xxxx.ru,admin@xxxx.ru${black}" echo -e "а также лежит в домашней папке с именем ${green}logIPADDR.rar${black}" echo "при наличии опции nosend лог не отправляется и не пакуетcя - остается в домашней папке" exit 1 fi cd /home/$userl # dates datebeg=`echo $1 |awk -F- '{print $2$1}'` yearbeg=`echo $1 |awk -F- '{print $3}'` if [ -z $yearbeg ] ; then yearbeg=$year ; fi dateend=`echo $2 |awk -F- '{print $2$1}'` yearend=`echo $2 |awk -F- '{print $3}'` if [ -z $yearend ] ; then yearend=$year ; fi # timestamps timebeg=`date --date="${yearbeg}${datebeg}" +%Y%m%d"0300"` timeend=`date --date="${yearend}${dateend} next day" +%Y%m%d"0500"` # files for compare cd /var/log/dump sudo touch -t ${timebeg} nachalo${userl}$$ sudo touch -t ${timeend} konec${userl}$$ ipaddr=${3} echo -e "${green}Lets's begin on xxxxx:${black}" # grep from dump echo > /home/${userl}/log${ipaddr} for i in `find /var/log/dump/ -type f -newer nachalo${userl}$$ ! -newer konec${userl}$$|grep dump/dump` ; do echo "progress in ${i}:" bar ${i} | zgrep "${ipaddr} " >> /home/${userl}/log${ipaddr} done # clear trash sudo rm -f /var/log/dump/nachalo${userl}$$ /var/log/dump/konec${userl}$$ cd /home/${userl} # grep from dump of xxxxx ssh ${userl}@xxxxx "sudo dumpget $ipaddr $timebeg $timeend" >> log${ipaddr} # begin line echo -e " date\t time\tin address\tout address\tbytes" > log${ipaddr}_ # clear prev and next day from log & sort # begin very long line :) grep -v `date --date="${yearbeg}${datebeg} 1 day ago" +%Y"-"%m"-"%d` log${ipaddr} |\ grep -v `date --date="${yearend}${dateend} next day" +%Y"-"%m"-"%d`|sort|\ awk '{print $1,$2" "$3"\t"$4"\t"$6}' >> log${ipaddr}_ # end very long line :) # summ of incoming & outgoing bytes from client echo -e "${redy}Client with ip ${ipaddr} get:" awk -v ipadr=${ipaddr} '$4==ipadr {sum+=$5};END {print "incoming: "sum" bytes"}' log${ipaddr}_ |tee -a log${ipaddr}_ awk -v ipadr=${ipaddr} '$3==ipadr {sum+=$5};END {print "outgoing: "sum" bytes"}' log${ipaddr}_ |tee -a log${ipaddr}_ echo -e $black # encoding for lamo OS todos log${ipaddr}_ # if no pack & mail if [ $4 == "nosend" ] ; then echo -e "${green}No pack and send, file with log: /home/${userl}/log${ipaddr}_${black}" rm log${ipaddr} exit 0 fi # pack to send echo -e "${green}Pack to RAR...${black}" rm log${ipaddr}.rar 2>/dev/null rar a log${ipaddr}.rar log${ipaddr}_ && rm log${ipaddr}_ log${ipaddr} # ...any baton :).... echo -e "${green}Send on ${green}support@internet2.ru,admin@internet2.ru${black}" # send pack to mail & clear mpack -s "Логирование клиента ${ipaddr} c $1 по $2" -c application/octet-stream log${ipaddr}.rar support@xxxx.ru,admin@xxxx.ru # end на соседнем роутере лежит такой скрипт: cat /usr/local/bin/dumpget #! /bin/bash # script run from xxxxx - /usr/local/bin/xlogir # variables userl=$SUDO_USER green="\033[01;32m" black="\033[00m" timebeg=$2 timeend=$3 # go & clean cd /var/log/dump rm nachalo${userl}* konec${userl}* >/dev/null 2>&1 #touch timestamps touch -t ${timebeg} nachalo${userl}$$ touch -t ${timeend} konec${userl}$$ ipaddr=$1 echo -e "${green}Let's begin on xxxxxx:${black}" >&2 # grep of dump for i in `find /var/log/dump/ -type f -newer nachalo${userl}$$ ! -newer konec${userl}$$|grep dump/dump` ; do echo "progress in ${i}:" >&2 bar ${i} | zgrep "$ipaddr " done # clean after work rm nachalo${userl}$$ konec${userl}$$