Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
ein script als du meter ersatz
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
zbled
Apprentice
Apprentice


Joined: 18 Jun 2002
Posts: 216
Location: Bukowski's Piano Bar

PostPosted: Wed Oct 16, 2002 7:32 pm    Post subject: ein script als du meter ersatz Reply with quote

sodala, da mein provider meinte, mich auf mein 10 gb transfervolumenslimit hinweisen zu müssen, habe ich mir ein script gebastelt, welches mir das down- und uploadvolumen pro sitzung anzeigt, wegsichert, summiert, usw.. vielleicht nützt es ja euch auch :)

die ausführbahre datei (ich habe sie sumtraffic genannt) in /etc/init.d.

Quote:

#!/sbin/runscript

depend() {
need net
}

start() {
ebegin "Starting SumTraffic "
datum=$(date +%d.%m.%Y)
monat=$(date +%m%Y)

#überprüfung, ob die datei /var/log/updown existiert, falls nicht = anlegen
if [ ! -f /var/log/updown ] ; then
echo 0 > /var/log/updown
echo die datei /var/log/updown wurde angelegt
fi

#überprüfung, ob die datei /var/log/monatupdo existiert, falls nicht = anlegen
if [ ! -f /var/log/monatupdo ] ; then
echo $monat > /var/log/monatupdo
echo die datei /var/log/monatupdo wurde angelegt
fi

#überprüfung des monats
if [ `cat /var/log/monatupdo` != $monat ] ; then
sum=0; for i in `cat /var/log/updown`; do ((sum+=i));done;
mv /var/log/updown /var/log/$datum.UPDOWN
echo 0 > /var/log/updown
echo Die Datei wurde unter dem Namen $datum.UPDOWN weggesichert
echo $datum: Transfervolumen des vergangenen Monats: $sum MB ';)'

#standard
else
sum=0; for i in `cat /var/log/updown`; do ((sum+=i));done;
echo $datum: bisher heruntergeladen: $sum MB. verbleibend: $[10240-$sum] MB
fi
eend $? "Failed to start SumTraffic"
}

stop() {
ebegin "Stopping SumTraffic "

#generelle variablen definieren

datum=$(date +%d.%m.%Y)
monat=$(date +%m%Y)

#Wert für die monatsüberprüfung in textdatei schreiben
echo $monat > /var/log/monatupdo

#up und downloadvolumen ermitteln
up=$(/sbin/ifconfig eth0 | grep "RX bytes" | gawk '{print $6}' | gawk -F':' '{print $2}');up=$[$up/1048576]
down=$(/sbin/ifconfig eth0 | grep "RX bytes" | gawk '{print $2}' | gawk -F':' '{print $2}');down=$[$down/1048576]

#prüfen, ob eventuell die summe von up und download > 0
summe=$[$up+$down]
if [ $summe = 0 ] ; then
up=$(/sbin/ifconfig eth0 | grep "RX bytes" | gawk '{print $6}' | gawk -F':' '{print $2}')
down=$(/sbin/ifconfig eth0 | grep "RX bytes" | gawk '{print $2}' | gawk -F':' '{print $2}')
summe=$[$up+$down];summe=$[$summe / 1048576]
echo $summe >> /var/log/updown
up=0;down=$summe

#falls summe von up und download immer noch < 0 dann 1 mb annehmen
if [ $summe = 0 ] ; then
up=0;down=1
echo $down >> /var/log/updown
fi

#ansonsten die tatsächlichen werte übernehmen
else
echo $down >> /var/log/updown
echo $up >> /var/log/updown
fi

sum=0; for i in `cat /var/log/updown`; do ((sum+=i));done;

#zusammenfassung ausgeben
echo $datum: heute: $[$up+$down] MB insgesamt: $sum MB verbleibend: $[10240-$sum] MB
eend $?
}



Quote:

anzeige:

beim start:

* Starting SumTraffic ...
16.10.2002: bisher heruntergeladen: 3796 MB. verbleibend: 6444 MB [ ok ]

beim beenden (herunterfahren)

* Stopping SumTraffic ...
16.10.2002: heute: 93 MB insgesamt: 3796 MB verbleibend: 6444 MB [ ok ]



ausserdem habe ich noch basierend auf dem script ein kleineres script zum manuellen anzeigen des aktuellen down- und uploadvolumens der sitzung gebastelt:

Quote:


datum=$(date +%d.%m.%Y)

up=$(/sbin/ifconfig eth0 | grep "RX bytes" | gawk '{print $6}' | gawk -F':' '{print $2}');up=$[$up/1048576]
down=$(/sbin/ifconfig eth0 | grep "RX bytes" | gawk '{print $2}' | gawk -F':' '{print $2}');down=$[$down/1048576]

sum=0; for i in `sudo cat /var/log/updown`; do ((sum+=i));done;
echo $datum: down: $down MB up: $up MB heute: $[$up+$down] MB >> /var/log/syslog
echo $datum: insgesamt: $sum MB verbleibend: $[10240-$sum] MB >> /var/log/syslog


Quote:

anzeige:
16.10.2002: down: 42 MB up: 52 MB heute: 94 MB
16.10.2002: insgesamt: 3703 MB verbleibend: 6537 MB


da ich mir die syslog ständig am bildschirm anzeigen lasse, wird das programm stündlich von fcron ausgeführt und in die logdatei geschrieben

schimpft nicht wegen der variablenbezeichnung, dem scriptaufbau usw.. ich bin kein programmierer ;)
Back to top
View user's profile Send private message
KiLLaCaT
Guru
Guru


Joined: 24 Jul 2002
Posts: 306
Location: Linz, Austria

PostPosted: Wed Oct 16, 2002 8:13 pm    Post subject: Reply with quote

recht schön dein srcipt,
aber mein provider setzt mir keine Limits( :lol: :lol: HAHA)

jax
Back to top
View user's profile Send private message
Larde
Guru
Guru


Joined: 07 Jun 2002
Posts: 313
Location: Duesseldorf, Germany

PostPosted: Wed Oct 16, 2002 8:26 pm    Post subject: Reply with quote

Quote:
aber mein provider setzt mir keine Limits


Me too! :-)

Aber mal was anderes: Im Skript wird nur auf eth0 gegreppt. Wenn ich mir jetzt aber mal meine ifconfig Ausgaben ansehe, habe ich
Code:
eth0      Link encap:Ethernet  HWaddr 00:E0:7D:B8:AA:82 
    [...]
          RX packets:33914191 errors:0 dropped:0 overruns:0 frame:0
          TX packets:33607937 errors:0 dropped:0 overruns:0 carrier:0
          collisions:63953 txqueuelen:100
          RX bytes:786642187 (750.2 Mb)  TX bytes:1073786318 (1024.0 Mb)
          Interrupt:11 Base address:0x8000
[snip]
ppp0      Link encap:Point-to-Point Protocol 
       [...]
          RX packets:5122298 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5249940 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:3285683697 (3133.4 Mb)  TX bytes:2298152309 (2191.6 Mb)


Will sagen, ppp0 hat viel mehr gezählt als eth0. Hmmm....

Wieder was lernen muß,
Larde.
_________________
Someday this will be my home... http://moonage.net/
I'll make you a deal
I'll say I came from Earth and my tongue is taped
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum