"Fossies" - the Fresh Open Source Software Archive

Member "aif-2.1.1/share/arno-iptables-firewall/plugins/traffic-accounting-log-rotate" (16 Sep 2020, 538 Bytes) of package /linux/privat/aif-2.1.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "traffic-accounting-log-rotate": 2.1.0_vs_2.1.1.

    1 #!/bin/sh
    2 
    3 log_file="/var/log/traffic-accounting.log"
    4 keeps=13
    5 
    6 log_rotate()
    7 {
    8   # $1 = filename
    9   # $2 = keep count
   10   filename="$1"
   11 
   12   if [ -f "$filename.$2" ]; then
   13     rm -f "$filename.$2"
   14   fi
   15 
   16   for x in `seq $(($2 + 1)) -1 1`; do
   17     if [ -f "$filename.$x" ]; then
   18       mv "$filename.$x" "$filename.$(($x + 1))"
   19     fi
   20   done
   21 
   22   if [ -f "$filename" ]; then
   23     mv "$filename" "$filename.1"
   24     
   25     # Reset counters
   26     cat "$filename.1" |awk '{ print $1" "$2" 0 0" }' > "$filename"
   27   fi
   28 }
   29 
   30 
   31 # main
   32 log_rotate "$log_file" $keeps
   33 
   34