#!/bin/sh

SCRIPTPATH=$( cd "$(dirname "$0")" ; pwd -P )

if [ ! -e "${SCRIPTPATH}/config" ]; then
    echo "Config file not found!"
    exit 120
    fi

. ${SCRIPTPATH}/config

exit_ifrun
create_lock

#YY=`date -d yesterday +%Y`
#MM=`date -d yesterday +%m`
#DD=`date -d yesterday +%d`
YY=2019
MM=04
DD=24

SAVE_PATH=/mnt/md0/stat/${YY}/${MM}/${DD}/
FLOW_DATA='/mnt/md0/stat/flow-data'

[ ! -e "${SAVE_PATH}" ] && mkdir -p ${SAVE_PATH}

DATA=`ls ${FLOW_DATA}/nfcapd.* 2>/dev/null | grep -v nfcapd.current`
[ -z "${DATA}" ] && exit 6

for i in $DATA; do
/bin/nfdump -N -r ${i} -q -o 'fmt:%ts;%pr;%sa;%da;%sp;%dp;%ipkt;%ibyt;%in;%out' | /opt/Eye/scripts/parse_flow.pl 25
[ $? -eq 0 ] && mv -f $i ${SAVE_PATH}
done

remove_lock

exit 0
