As I've recently changed to an ISP that kicks me off after 2 hours, I've
knocked together a little program that relies on the fact that when you go
online, the pppd daemon creates /var/run/pppX.pid, the little program I've
hacked together does a stat on the file and calculates the time you've
been online.

Enjoy - I hereby place this program into the public domain to be freely
copied, hacked, compiled and used anywhere so long you acknowledge me as
the author.

/* Written by Alex Buell <[EMAIL PROTECTED]> */
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/stat.h>

#define PPP_PID "/var/run/ppp0.pid"

int main(void)
{
        time_t t1 = time(0);
        struct stat st;
        long hours, minutes, seconds;

        if (stat(PPP_PID, &st) < 0)
        {
                printf("Failed to retrieve stat for %s\n", PPP_PID);
                return 1;
        }

        seconds = t1 - st.st_atime;
        hours = seconds / 3600;
        if (hours * 3599 < seconds)
                seconds -= (hours * 3600);
        minutes = seconds / 60;
        if (minutes * 59 < seconds)
                seconds -= (minutes * 60);
        if (hours * minutes < seconds)
                seconds -= hours * minutes;

        if (hours != 0)
                printf("%ldh ", hours);
        if (minutes != 0)
                printf("%ldm ", minutes);
        printf("%lds online\n", seconds);
        return 0;
}

Cheers, 
Alex
-- 
The quality of your life will be determined by 
the quality of the people in your life.


-
To unsubscribe from this list: send the line "unsubscribe linux-ppp" in
the body of a message to [EMAIL PROTECTED]

Reply via email to