#! /bin/sh # Convert the required portion of a Argus netflow to ArgusNCSA format # Ra options: -A -c -G -n # Argus version: 2.0.5 # Usage: Usage: argus-NCSA-convert ra_client argusfile start_time end_time #set -x # used for debugging set +x if [ ! $# -eq 4 ]; then echo "Notice: This script only works with argus 2.0.5" 1>&2 echo "Usage: argus-NCSA-convert ra_client argusfile start_time(hh:mm:ss) end_time(hh:mm:ss)" 1>&2 echo "Example: argus-NCSA-convert /usr/local/bin/ra someargusfile 06:21:00 17:42:35" 1>&2 exit 1 fi trap 'exit 1' 1 2 3 15 # catch signals trap '' 0 # exit correctly #test the existence of a proper ra ra=`which $1` if [ $? -ne 0 -o ! -x "$ra" ]; then echo "argus-NCSA-convert: $1 not found or not executable" 1>&2 exit 1 fi argusfile="$2" if [ ! -f "$argusfile" ]; then echo "argus-NCSA-convert: $argusfile not found or special file" 1>&2 exit 1 fi starttime="$3" endtime="$4" #build the file name shour=`echo "$starttime" | cut -d ":" -f1 2> /dev/null` smin=`echo "$starttime" | cut -d ":" -f2 2> /dev/null` ssec=`echo "$starttime" | cut -d ":" -f3 2> /dev/null` ehour=`echo "$endtime" | cut -d ":" -f1 2> /dev/null` emin=`echo "$endtime" | cut -d ":" -f2 2> /dev/null` esec=`echo "$endtime" | cut -d ":" -f3 2> /dev/null` outputfilename="${argusfile}_${shour}-${smin}-${ssec}_${ehour}-${emin}-${esec}" echo "generating $outputfilename ..." #sed: to convert Dos, Mac format to Unix format #awk: chop the line to make each line be of the same length #note that awk does not count "\n", so length in awk = wc - 1 #so the reclen is set to 142 here $ra -A -c -G -n -t ${starttime} - ${endtime} -r $argusfile - | \ sed -e 's/\r\n/\n/' -e 's/\r/\n/' | \ awk '{ reclen = 142; if ( length == reclen ) print $0; else if ( length > reclen ) print substr($0, 1, reclen) }' \ > $outputfilename #chmod g+r $outputfilename