[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Tool um traffic über ppp abzuspeichern...



So, habe mal mein Script abgeändert und diejenigen die es interessiert,
es ist angehängt...

Sollte in

    ~/bin/tdtrafficcounter

liegen und symlinks in

    /etc/network/if-up.d/tdtrafficcounter
    /etc/network/if-down.d/tdtrafficcounter

haben.

Außerdem sollten unter Umständen die Variablen

    LOG_DIR    TMP_DIR    CHMOD    CHOWN

am Anfang des Scripts angepaßt werden.

Thanks, Greetings and nice Day
    Michelle Konzack
    Systemadministrator
    24V Electronic Engineer
    Tamay Dogan Network
    Debian GNU/Linux Consultant


-- 
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack   Apt. 917                  ICQ #328449886
+49/177/9351947    50, rue de Soultz         MSN LinuxMichi
+33/6/61925193     67100 Strasbourg/France   IRC #Debian (irc.icq.com)
#!/bin/bash
#                                                                    #
# Copyright 2007, Michelle Konzack All rights reserved.              #
#                                                                    #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions #
# are met:                                                           #
#                                                                    #
# 1. Redistributions of source code  must retain the above copyright #
#    notice, this list of conditions and the following disclaimer.   #
#                                                                    #
# 2. Redistributions  in  binary  form   must  reproduce  the  above #
#    copyright  notice, this  list of  conditions and  the following #
#    disclaimer in the documentation and/or other materials provided #
#    with the distribution.                                          #
#                                                                    #
# 3. Neither  the name  of Michelle Konzack  nor the  names of  its #
#    contributors may be used to endorse or promote products derived #
#    from this software without specific prior written permission.   #
#                                                                    #
# THIS  SOFTWARE IS  PROVIDED BY  MICHELLE KONZACK  AND CONTRIBUTORS #
# ``AS IS'  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,  INCLUDING, BUT #
# NOT  LIMITED TO,  THE  IMPLIED WARRANTIES  OF MERCHANTABILITY  AND #
# FITNESS  FOR A  PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT #
# SHALL MICHELLE KONZACK OR  CONTRIBUTORS  BE LIABLE FOR ANY DIRECT, #
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES #
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR #
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) #
# HOWEVER  CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN #
# CONTRACT,  STRICT  LIABILITY,  OR TORT  (INCLUDING  NEGLIGENCE  OR #
# OTHERWISE) ARISING  IN ANY WAY  OUT OF  THE USE OF  THIS SOFTWARE, #
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                 #
#                                                                    #

VERSION=0.1.0

AUTHORNAME="Michelle Konzack"
AUTHORMAIL="linux4michelle@freenet.de"
LICENSE="This tool is under GNU GPL version 3.0"

#=======================================================================

LOG_DIR=/var/log/tdtrafficcounter
TMP_DIR=/var/log/tdtrafficcounter

CHMOD=664
CHOWN=root:adm

#=======================================================================

LOGNAME=${LOG_DIR}/$(date +%Y-%m).log

mkdir -p	${LOG_DIR} ${TMP_DIR}
chown ${CHOWN}	${LOG_DIR} ${TMP_DIR}

#=======================================================================

DATE=$(date +"%Y-%m-%d %H:%M:%S")
HN=$(hostname --short)

RX_FILE=${TMP_DIR}/${IFACE}.start_rx
TX_FILE=${TMP_DIR}/${IFACE}.start_tx
S_TIME=${TMP_DIR}/${IFACE}.start_time

TRAF_NOW=$(grep "${IFACE}" /proc/net/dev |tr -s ' ' |sed "s|.*${IFACE}:||;s|^ ||" |cut -d ' ' -f1,9)
TX_NOW=$(echo "${TRAF_NOW}" |cut -d ' ' -f1)
RX_NOW=$(echo "${TRAF_NOW}" |cut -d ' ' -f2)

TIME_NOW=$(date +%s)

########################################################################
#  
#  
#  
########################################################################

echo -n "${DATE} [${HN}] IFACE=${IFACE}, MODE=${MODE}" >>${LOGNAME}

########################################################################
#  
#  We start our traffic counter
#  
########################################################################
if   [ "${MODE}" = "start" ] ; then
  echo "${TIME_NOW}"	>${S_TIME}
  echo "${RX_NOW}"	>${RX_FILE}
  echo "${TX_NOW}"	>${TX_FILE}
  #=====================================================================
  echo "" >>${LOGNAME}

########################################################################
#  
#  We stop our traffic counter
#  
########################################################################
elif [ "${MODE}" = "stop" ] ; then
  if [ -f ${RX_FILE} ] ; then
    RX_OLD=$(cat ${RX_FILE})
    rm -f ${RX_FILE}
  else
    RX=0
  fi
  #---------------------------------------------------------------------
  if [ -f ${TX_FILE} ] ; then
    TX_OLD=$(cat ${TX_FILE})
    rm -f ${TX_FILE}
  else
    TX=0
  fi
  #=====================================================================
  TX_DIFF=$((TX_NOW-TX_OLD))
  if [ ${TX_DIFF} -lt 0 ] ; then
    TX_DIFF=overrun
  fi
  #---------------------------------------------------------------------
  RX_DIFF=$((RX_NOW-RX_OLD))
  if [ ${RX_DIFF} -lt 0 ] ; then
    RX_DIFF=overrun
  fi
  #---------------------------------------------------------------------
  if [ -z "${TX_FLAG}" ] && [ -z "${RX_FLAG}" ] ; then
    TRAFFIC=$((TX_DIFF+RX_DIFF))
  else
    TRAFFIC=overrun
  fi
  #=====================================================================
  if [ -f ${S_TIME} ] ; then
    STOPTIME=$(cat ${S_TIME})
    RTIME=$((TIME_NOW-STOPTIME))
      HOURS=$((RTIME/3600))
      H_TMP=$((HOURS*3600))
      SECS=$((RTIME-H_TMP))
      MINS=$((SECS/60))
      M_TMP=$((MINS*60))
      SECS=$((SECS-M_TMP))
    if [ ${#HOURS} -lt 2 ] ; then HOURS=0${HOURS} ; fi
    if [ ${#MINS}  -lt 2 ] ; then  MINS=0${MINS}  ; fi
    if [ ${#SECS}  -lt 2 ] ; then  SECS=0${SECS}  ; fi
    rm -f ${S_TIME}
  else
    HOURS=00
    MINS=00
    SECS=00
  fi
  #=====================================================================
  echo ", TX=${TX_DIFF}, RX=${RX_DIFF}, TRAFFIC=${TRAFFIC}, RUNNING=${HOURS}:${MINS}:${SECS}" >>${LOGNAME}

fi

########################################################################

chmod ${CHMOD}	${LOG_DIR}/*
chown ${CHOWN}	${LOG_DIR}/*

Attachment: signature.pgp
Description: Digital signature


Reply to: