Total monthly upload/download: is there a PET?

Booting, installing, newbie
Message
Author
Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#21 Post by Sylvander »

1. "What the hell are you doing here?"
Re-using [almost] any old script file, except that particular file had code for loading a program, except it was the wrong program, so I changed the program that was to be loaded [and the name of the file to make it appropriate].
I tried to get too smart here; I notice load_past_internet _usage in the /root/Startup folder, so I deleted the copy of AutoRunPusageMon in there.
Now when I right-click load_past_internet _usage and choose Open, I get the warning "ERROR - no datefile found" as in screenshot shown above.

2. "Please tell me what that Window says"
See screenshot 00 below.
Attachments
00.jpg
(101.08 KiB) Downloaded 708 times
User avatar
William (Dthdealer)
Posts: 146
Joined: Thu 30 Oct 2008, 06:41
Location: Australia (GMT +10)

Pusagemon v0.2

#22 Post by William (Dthdealer) »

This code may not be 100%
However it will not damage your system AFAIK.

If anything does go wrong (eg error messages, hang on shutdown) I'll be able to tell you exactly how to fix the problem if you explain what it is.

This time the script works perfectly! However it still will not work if rebooting, I'll add the code to edit the /sbin/reboot file in the next version.

What this is
Pusagemon (Puppy USAGE MONitor) is a simple script that installs itself into two files in the system. Whenever you shutdown Puppy, a file is saved that contains how much of your internet monthly cap you have used. When you turn your computer on the other file loads this information again.

Every month the counter is reset to 0, the old statistics being deleted.

Once installed you can run the same file you used to install everything (pusagemon) to view your usage of your cap.

Note that the utility only starts monitoring your usage once you install it. Any previous usage in that month is unknown.

How to remove the old version {IMPORTANT}
The new installation will not work if you do not do this!
  1. Right click the desktop or press the menu button
  2. Click Utility and then Rxvt terminal emulator
  3. Select the three lines of the text in the codebox below as if you are going to copy them.
  4. Press the scroll-wheel of your mouse in (or both right-click and left-click at the same time if you don't have a scroll-wheel) with your mouse positioned over the RXVT window to paste the line into RXVT. This is the way things were pasted in Linux before Ctrl+C and Ctrl+V
  5. Press enter with the RXVT window selected so the lines are interpreted

Code: Select all

rm ~/Startup/load_past_internet_usage
grep -v iptables /sbin/poweroff > /tmp/poo
mv /tmp/poo /sbin/poweroff

How to install and use
  1. IF YOU USED THE PREVIOUS VERSION I ATTACHED FIRST READ THE SECTION ABOVE THIS 'HOWTO REMOVE OLD VERSION'
  2. Click on the link on the bottom of my post to download the file.
  3. Save the file anywhere
  4. Open it up and extract the contents to /root/my-applications/bin/ (home-->my-applications-->bin)
  5. Browse to there in ROX filer
  6. To run, click on the file. Alternatively you can type pusagemon at a terminal.
  7. Answer yes to the first two questions. They will not come up again
  8. {OPTIONAL} Drag the file onto your desktop to make a shortcut
  9. {OPTIONAL} Right click the shortcut on your desktop, and click Edit Item. Now set a key shortcut.
    Whenever you press these keys (in any application) your uploads and downloads will show at the top of your screen
Attachments
pusagemon.tar.gz
Download this file!
Version 0.2
(3.18 KiB) Downloaded 335 times
Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#23 Post by Sylvander »

Completed the steps above [excluded the optional shortcut on the desktop], and it appears to be working as it aught. :D

Haven't tried rebooting; will do so soon.
Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#24 Post by Sylvander »

At reboot...
Once into the desktop...
1. There is displayed the "ERROR - no datefile found" as screenshot shown previously....
And no green display of usage. :(

2. Now, if I right-click and "Open" /root/my-applications/bin/pusagemon the program doesn't run.
[I'm now beginning to wonder if I imagined this?]

3. If I enter the command pusagemon in a terminal, the program runs as it aught and displays the green usage totals.

4. Now, if I right-click and "Open" /root/my-applications/bin/pusagemon the program DOES run. :? :D

5. Will reboot again and see what happens.
Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#25 Post by Sylvander »

At reboot I got [exactly?] the same, except at step 2 the program ran.
User avatar
William (Dthdealer)
Posts: 146
Joined: Thu 30 Oct 2008, 06:41
Location: Australia (GMT +10)

#26 Post by William (Dthdealer) »

If you read my post you will find out the script doesn't save if you reboot, only if you shutdown.

Sorry, as I said earlier I'll add that part in a jiff. Then all there is to do is replace the yaf-splash with a tray icon and make the script loop.

The reboot fix will be here tomorrow.
Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#27 Post by Sylvander »

Had a problem...
BoxPup wouldn't close down. [Never seen that before]
Decided to restore my most recent backup of the contents of the BoxPup partition [2009 Dec 11th].
That took things back to then.
Will need to redo all changes previously made since then that are still desirable.
That will include the programs here.
Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#28 Post by Sylvander »

Reinstalled using "How to install and use" instructions, but when I shut down, then restart...
Once back into the desktop the program doesn't auto-run.

It runs if I use the pusagemon command.

For the moment...
I'll eliminate it by restoring the backup [of 2009 Dec 11th] once again.
User avatar
MrToad
Posts: 62
Joined: Thu 13 Dec 2007, 22:58
Location: East Devon, GB

#29 Post by MrToad »

@ William,

I have had the same result in Puppy 4.21 as Sylvander has in BoxPup - my system won't shut down using the gui's shutdown command- it just dumps me at the system prompt. I can type xwin there and get back to the desktop, or I can type reboot and the system reboots OK (or I can switch off the power and make a bit of a mess), but typing poweroff results in a "Permission denied" message, which is a bit puzzling as I am running as root... I think...

Anyway, naturally the reboot results in a message window from pusagemon telling me "Error - no datafile found" etc. On clicking "OK" the green splash appears.

It's nearly there... I am getting quite excited about this!

I appreciate that it might involve a lot of additional work, but would you think (please!) about arranging for two or more machines on a LAN to pool their pusagemon data and displaying the total in the tray-icon you are working on? Then it would be a substantially functionally-complete replacement for the NetWorx/Wine combination that I am currently using.

Re an autostart, I think that programs in the Startup folder are executed in alphabetic order - in which case if pusagemon is put there it should run after load_past_internet_usage and hopefully all will be well. I appreciate that there's no real point in an autostart until after you have it looping, but once that's working and the tray-icon is present then it would be great to have it autostarting.

Thanks for taking up this little project, William. And thanks, Sylvander, for posting the question that started this interesting thread, as apart from anything else this thread has piqued my interest in scripting. Right now I am examining pusagemon's line 234 onwards to see if even a novice like me can figure out what is happening with the shutdown before William's fix appears - which would be a REAL buzz!.

MrToad
User avatar
MrToad
Posts: 62
Joined: Thu 13 Dec 2007, 22:58
Location: East Devon, GB

#30 Post by MrToad »

Well, I discovered that the /sbin/poweroff script that puseagemon made, wasn't running because it wasn't executable. Once I made it executable my Puppy 4.21 shut down cleanly.

However, I still wasn't getting /etc/pusagemon/iptablesave made, so the window appeared after shutdown and booting up again...

I then discovered that with all my fiddling about, I had somehow managed to add a space in a word in the command-line at line 245 of the script :-( because on starting from scratch and re-downloading pusagemon in order to check everything out afresh, not only did it now work properly but the space was not there... Moral: don't fiddle with the original file... only work on copies :-)

Anyway, it turns out that all I needed to do (on a clean system) was to decompress the downloaded script, run it, put the file in root/my-applications, make /sbin/poweroff executable before doing a shutdown - and it works! A click on the icon gives me a small green splash with my cumulative usage, and after a few seconds it goes away. Very tidy!

I'm looking forward to the looping tray-icon version. :-)

MrToad
User avatar
William (Dthdealer)
Posts: 146
Joined: Thu 30 Oct 2008, 06:41
Location: Australia (GMT +10)

#31 Post by William (Dthdealer) »

Have not been near a computer for the past two days.
Sylvander wrote:Had a problem...
BoxPup wouldn't close down. [Never seen that before]
Decided to restore my most recent backup of the contents of the BoxPup partition [2009 Dec 11th].
That took things back to then.
Will need to redo all changes previously made since then that are still desirable.
That will include the programs here.
Easily fixable
Which means if you use a computer, then shut it down before turning the next one on, the new computer will have behind statistics

The most likely problem is that /sbin/poweroff hasn't been made executable. 'Executability' is similar to the 'read only' setting, but instead of making the file untouchable it stops or allows the file to be run as a program. Windows has no equivalent.

Open up RXVT ( Menu-->Utilities-->RXVT terminal emulator ) and type the following in, then press enter.

Code: Select all

chmod a+x /sbin/poweroff
You can read my previous post on how to copy and paste into rxvt if you don't want to write all of that out.
MrToad wrote:Well, I discovered that the /sbin/poweroff script that puseagemon made, wasn't running because it wasn't executable. Once I made it executable my Puppy 4.21 shut down cleanly.

However, I still wasn't getting /etc/pusagemon/iptablesave made, so the window appeared after shutdown and booting up again...

I then discovered that with all my fiddling about, I had somehow managed to add a space in a word in the command-line at line 245 of the script :-( because on starting from scratch and re-downloading pusagemon in order to check everything out afresh, not only did it now work properly but the space was not there... Moral: don't fiddle with the original file... only work on copies :-)

Anyway, it turns out that all I needed to do (on a clean system) was to decompress the downloaded script, run it, put the file in root/my-applications, make /sbin/poweroff executable before doing a shutdown - and it works! A click on the icon gives me a small green splash with my cumulative usage, and after a few seconds it goes away. Very tidy!

I'm looking forward to the looping tray-icon version. :-)

MrToad
Thanks MrToad!

I'll fix the problem of /sbin/poweroff (and /sbin/reboot) not being made executable in the next version.

Sylvander wrote:Reinstalled using "How to install and use" instructions, but when I shut down, then restart...
Once back into the desktop the program doesn't auto-run.

It runs if I use the pusagemon command.

For the moment...
I'll eliminate it by restoring the backup [of 2009 Dec 11th] once again.
The program technically is 3 files:
Pusagemon
  • This is the file you download
  • I install both of the other scripts shown below
  • The use must manually run me. I only run that once and then quit until clicked on again.
  • I am the only script that displays the internet usage information to the user
/sbin/poweroff
  • I consist of three lines, on of which is a comment
  • I am inserted into the current /sbin/poweroff when installed
  • I display no messages or error messages
  • I save the internet usage so it can be loaded next boot
  • I save a datefile so load_past_internet_usage knows when to start from scratch
  • I only run once through when the system shuts down
~/Startup/load_past_internet_usage
  • I am the script that loads the internet usage information when the computer starts up
  • I only run once - when the system has finished loading the graphical system (X)
  • I display the error message 'no datefile found'
  • I load the file saved by /sbin/poweroff
  • I delete the past internet usage if it was from the last month
I appreciate that it might involve a lot of additional work, but would you think (please!) about arranging for two or more machines on a LAN to pool their pusagemon data and displaying the total in the tray-icon you are working on? Then it would be a substantially functionally-complete replacement for the NetWorx/Wine combination that I am currently using.
I'd need information on where to start to learn how to make computer communicate over LAN. Unless someone can point me in the right direction, I'm clueless on how to start.

This would be a great feature.

However I can see a few downsides to it. These are probably problems with the NetWorx program anyway
  • Unless you want to go through your router's port redirection configuration I'd have to write a cpu cycle and network wasting script that sends packets to all of the clients connected to the router perioducally
  • It would be a security risk - if one of the computers is infected with even a Windoze virus then Puppy may receive odd packets. These would screw up pusagemon's configuration and possibly slow your web browsing down if you are bombarded with Windoze infection packets. Nothing would be damaging of course
  • It would be very difficult to setup a main computer that has a slightly different script that adds the whole LAN's network usage as:
    • That computer cannot be disconnected from the network as it may get a new local IP when re-connected. Laptops shut-off their network cards after shutting down, so laptops couldn't be used as the pusagemon 'server'
    • Port forwarding would be required. Hands up who knows what those words mean.
    So I would have to set a distributed system, where every time a computer boots it pokes to see any other computers in the network and loads the latest computer's stats to add the rest (the last computer used and on) bla bla bla
  • If you shutdown your computer after browsing the web (Computer A), and then turn another on (Computer B), computer B will not have the statistics from computer A. If I then turned computer A on, for the problem to be fixed I would have to have a script looping (wasting CPU cycles) on computer B that waits for update information sent when computer A boots.
None or these scripts are constantly running. They simply save, fetch and load statistics from IPtables, a component of the Linux kernel.


None the less if someone can point me in the right direction I'll be more than happy to start writing that in.
User avatar
MrToad
Posts: 62
Joined: Thu 13 Dec 2007, 22:58
Location: East Devon, GB

#32 Post by MrToad »

William,

You make some very good points about the drawbacks of attempting to achieve a cumulative total. The NetWorx solution allows this feature to be turned off, which removes that overhead, but of course that doesn't remove the Wine overhead nor does it deal with the security issue. In the light of all this your tray-icon version of pusagemon for a single computer is probably the better option. And it would probably cater for the majority of needs.

But if you *were* to think of taking things further (I'm afraid my own technical knowledge of inter-computer communications is somewhat limited), the best suggestion I can come up with is to set up a shared folder between Puppies and copy the iptables data from each computer to a file there at intervals and at shutdown, and read that file with a slightly-modified pusagemon. I think file-sharing is already in many recent Puppies (in 4.21 it's in the Menu at Network>PcurlFtp) so that might not be too hard. And there's always the possibility of using a shared Dropbox folder for this.

I look forward with interest to seeing the "final" version of pusagemon.

And, William, the fact that you actually listed the code of pusagemon in your earlier post, and I had that little permissions problem, has got me interested in having a go at a bit of scripting for myself - so thank you! I might even see if I can get pusagemon working for a monthly-interval beginning on the 11th of each month, which is what my ISP's billing-period runs from... unless you get there first, of course. ;-)

MrToad
Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#33 Post by Sylvander »

1. "The most likely problem is that /sbin/poweroff hasn't been made executable"
Hmmm, looks to me to be executable already, and not needing fixed, however I did use your command but it made no difference.

(a) I began with a clean/restored system [i.e. no traces of any previous installation of pusagemon].

(b) Installed as per your "How to install and use" instructions.

(c) Checked the "Properties" of the /sbin/poweroff file [see screenshot below].
Looked to be OK, but I copied and "shift+insert"-ed the command:

Code: Select all

chmod a+x /sbin/poweroff
But it made no difference to the file properties.

(d) When I shut down [it does this ok], then restart...
Once back into the desktop, there is no display of the green totals.
Entering the pusagemon command produces the green totals for the session.

(e) There exists an empty /etc/pusagemon folder [as it should be?]
There is no /etc/pusagemon/savedate file [as it should be?]
Attachments
00.jpg
(27.62 KiB) Downloaded 848 times
User avatar
William (Dthdealer)
Posts: 146
Joined: Thu 30 Oct 2008, 06:41
Location: Australia (GMT +10)

#34 Post by William (Dthdealer) »

Sylvander wrote:
...

(c) Checked the "Properties" of the /sbin/poweroff file [see screenshot below].
Looked to be OK, but I copied and "shift+insert"-ed the command:

Code: Select all

chmod a+x /sbin/poweroff
But it made no difference to the file properties.

(d) When I shut down [it does this ok], then restart...
Once back into the desktop, there is no display of the green totals.
Entering the pusagemon command produces the green totals for the session.

(e) There exists an empty /etc/pusagemon folder [as it should be?]
There is no /etc/pusagemon/savedate file [as it should be?]
(c) The line isn't supposed to be inserted into the file! It is supposed to be written in the terminal to fix the permissions. However by the screenshot you have supplied there should not be any problem.

(d) I'm sorry to sound angry, but I have already answered this more than once.

THE PROGRAM DOES NOT AUTOMATICALLY SHOW THE RESULTS WHEN YOU TURN YOUR COMPUTER ON. YOU NEED TO RUN IT MANUALLY.

(e) That's odd. Are you running my latest version here? If you are not getting an error message at startup then it isn't empty.

Open up RXVT (Menu-->Utilities-->RXVT terminal emulator) and type this in.

Code: Select all

ls -la /etc/pusagemon
You should get information along the lines of this:

Code: Select all

total 12
drwxr-xr-x  2 root root 4096 2009-01-28 00:02 .
drwxr-xr-x 37 root root  220 2009-01-31 03:33 ..
-rw-r--r--  1 root root  213 2009-01-30 04:06 iptablesave
-rw-r--r--  1 root root   13 2009-01-30 04:06 savedate

I'll have at look at folder sharing in Puppy but for now I'll start reading the (x)dialog documentation.

AFAIK JWM applets are ordinary programs that fit into the tray. I'll see if I can squeeze xdialog to fit that bill.
User avatar
William (Dthdealer)
Posts: 146
Joined: Thu 30 Oct 2008, 06:41
Location: Australia (GMT +10)

#35 Post by William (Dthdealer) »

Code: Select all

Xdialog --no-buttons --tailbox filethatresultsaredumpedto 2 12
That makes a two-line (fits in JWM tray) 12-character long window. The file gets information in the following form appended to it periodically.

Code: Select all

U *uploads*
D *downloads*
So an example would be[quote=Example]U 452B
D 89760G[/quote]

There would be a script in the background that runs every 5 minutes. Every 2 hours ( 24 runs ) the Xdialog process would be killed, the file deleted and started again. This is because otherwise you would have a massive file building up over time ( 12 runs * 2 lines = 24 lines an hour).

Although very few Puppians have their system constantly running, we don't want Puppy to be like Windows 9x which died after a few days running.

Unfortunately Xdialog is failing me.

See the attached image. I can't get rid of the scrollbars!

Remember once it the tray the title bar and border would be gone, so it would fit.

Perhaps gtkdialog3 may be of service to me.
Attachments
poo.png
(2.71 KiB) Downloaded 854 times
Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#36 Post by Sylvander »

1. "It is supposed to be written in the terminal"
Exactly what I did.

2. "I'm sorry to sound angry, but I have already answered this more than once"
Sorry to be so dim, I've lost the plot, if I ever had it.

3. "THE PROGRAM DOES NOT AUTOMATICALLY SHOW THE RESULTS WHEN YOU TURN YOUR COMPUTER ON. YOU NEED TO RUN IT MANUALLY"
Oh shucks, is there no way to have it auto-display the running totals at startup?
I had it doing [something like] that by making a script file and locating it in the Startup folder.

4. "Are you running my latest version here?"
Yes.

5. "If you are not getting an error message at startup then it isn't empty"
I'm [now] getting NOTHING at startup [I think so anyway; need to check that]...
And now the folder has content [2 files; see screenshot 00].

6"Open up RXVT"
I'm using the Sakura terminal [the default terminal in BoxPup].

7"You should get information along the lines of this"
I do; see screenshot 01.
Attachments
00.jpg
(12.23 KiB) Downloaded 801 times
01.jpg
(56.23 KiB) Downloaded 817 times
User avatar
William (Dthdealer)
Posts: 146
Joined: Thu 30 Oct 2008, 06:41
Location: Australia (GMT +10)

#37 Post by William (Dthdealer) »

@Sylvander

1. The way you wrote you message made me believe you inserted the chmod line into /sbin/poweroff. Sorry

2. I'm not 100% at explaining things, this is my fault.

3. Seeing as load_past... starts with L and pusagemon starts with P, it would probably be safe to place a symlink or the file itself in ~/Startup.

5. Then everything should be working

6. Never used it, but it is still good 'ol BASH

7. Once again, everything should be working now.
Frank Cox
Posts: 378
Joined: Sun 01 Nov 2009, 06:05

Thanks

#38 Post by Frank Cox »

That is a neat program.

Does anyone here know of one that will show the connection speed for a dialup connection?
Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#39 Post by Sylvander »

1. "it would probably be safe to place a symlink or the file itself in ~/Startup"
(a) Did that, and the green display of totals is now auto-shown upon reaching the desktop. :D

(b) Strange thing:
I notice that the uploads FAR EXCEED the downloads. :?
Any idea why this would be so?
User avatar
William (Dthdealer)
Posts: 146
Joined: Thu 30 Oct 2008, 06:41
Location: Australia (GMT +10)

#40 Post by William (Dthdealer) »

I believe the uploads/downloads are the wrong way around. Can anyone confirm this?
Post Reply