[Solved] How to add new option for Connection Applet?

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

[Solved] How to add new option for Connection Applet?

#1 Post by puppy_apprentice »

I'm surfing internet via USB dongle and i have a few GB allowance. Need to store RX and TX to count how many free data from my allowance left. So far i've used a script like this:

Code: Select all

#!/bin/sh
date
netstat -ie | grep -A6 "$1" | grep "packets"
from terminal:

Code: Select all

>saveinetdata ppp0 >>inetdataused.txt
but a few times i've forgotten to call my script. So better solution will be if i could attach my script to Connection Applet option: Disconnect from network. So always when i will close connection i will store usage statistics.
Last edited by puppy_apprentice on Tue 13 Feb 2018, 19:54, edited 1 time in total.

matchpoint
Posts: 168
Joined: Fri 26 Jan 2018, 20:54

#2 Post by matchpoint »

Puppy_apprentice Dude!

Since I think you're pretty resourceful, and, depending on the connection manager you're running, I'd say you'll be able to take this advice and run with it!

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#3 Post by puppy_apprentice »

Thx for hint. I will try. But i need to execute my script just before closing internet connection. Puppy Connection Applet is showing Tx and Rx in a tooltip but when i choose disconnect option all values are resetting. My script showing the same values for Rx and Tx only when I'm connected. When I'm off my script is showing zeroes like Connection Applet.

I could use vnStat daemon, but my script is just enough for my needs. Does Puppy Connection Applet is using any script? Or i have to recompile (where i can find sources) it to add new option to store usage data?

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#4 Post by puppy_apprentice »

Ok, i've found something. PupDial is storing statistics (overall usage) in:

Code: Select all

/var/local/pupdial/isp1/
But it saves them only when you disconnect from internet using option form PupDial App. If you use Network Applet option: "Disconnect from network" last session usage is not added to previous. It will be better to save usage statistics for all connections scripts like: PupDial, Freesbee, GPRsConect using option "Disconnect from network" from Puppy Connection Applet. Who is author of this applet?

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#5 Post by MochiMoppel »

puppy_apprentice wrote:It will be better to save usage statistics for all connections scripts
May depend on the way you close your connection, but at least when you use the tray icon and choose "Disconnect from network" this should work:

Edit the script /usr/local/apps/Connect/AppRun . At the end find the section that handles the option --disconnect. The case statement ends the connection depending on the tool you are using, so whatever command you put in front of this case statement will be executed right before closing the connection. A good place to run your script:
  • --disconnect) #disconnect using default tool.
    saveinetdata ppp0 >>inetdataused.txt
    case $CURREXEC in
    net-setup.sh) exec /etc/rc.d/rc.network stop 1>&2 ;; #Dougal.
    pgprs-connect) pppd call gprs-disconnect-chatmm; killall pppd ;; #guessing, i need help here.
    pupdial) killall wvdial; killall pppd ;;
    pppoe_gui) pppoe_gui ;;
    connectwizard) connectwizard ;;
    Pwireless2) Pwireless2 ;;
    net_wiz_classic) net_wiz_classic ;;
    sns) /usr/local/simple_network_setup/rc.network stop ;;
    frisbee) [ -f /usr/local/bin/frisbee ] && /usr/local/frisbee/disconnect ;; #130104
    esac
    ;;
    *) exec /usr/local/bin/defaultconnect 1>&2 ;;
    esac

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#6 Post by puppy_apprentice »

My script saveinetdata:

Variant 1:

Code: Select all

actif=`route | grep "default" | awk '{ print $8 '}` #determine active interface
date >> /root/$actif-log.txt
netstat -ie | grep -A6 $actif | grep "packets" >> /root/$actif-log.txt
Variant 2:

Code: Select all

#!/bin/sh
actif=`route | grep "default" | awk '{ print $8 '}` #determine active interface
date >> /root/$actif-log.txt
ifconfig $actif | grep "bytes" >> /root/$actif-log.txt

1) have tried matchpoint solution:

There is no directory in Puppy /etc called 'network', 'if-down.d', 'if-post-down.d' and file 'interfaces'.
But i've made those:

In /etc i've made those:

Code: Select all

network
|-- if-down.d
|   `-- script
|-- if-post-down.d
|   `-- script
|-- if-pre-down.d
|   `-- script
`-- interfaces
script:

Code: Select all

#!/bin/sh
# filename: saveinetdata

if [ "$IFACE" = "ppp0" ]; then
  saveinetdata
fi
interfaces:

Code: Select all

iface ppp0 inet wvdial
If i want to get statistics i have to first use in terminal:

Code: Select all

ifup ppp0 #to configure interface
and later:

Code: Select all

ifdown ppp0 #to run script
ifdown give me the same result like my script used from terminal.

2) Mochimopel solution works as expected.

Code: Select all

--disconnect) #disconnect using default tool.
saveinetdata #or ifdown ppp0
case $CURREXEC in 

Post Reply