Quote:
Originally Posted by andygo
Hey!
I didn't solve THE problem
I need a software for the librarian to understand it...
I've got a couple of PC's in the school library with internet connection via ADSL
So I need some sort of account/billing system (like those, often used in cyber cafes) for the librarian to control the usege of internet & account usage
thanks
|
Hello.
How do you want to control the usage of internet & account usage ?
Do you just want some software that records every minute a student has been using the pc, and then calculate the cost for each student and minute ?
I just wrote this script and it seems to works fine.
It will calculate and report how many minutes a user has been
active, like
User king Total active time : 43 minutes
User media Total active time : 208 minutes
User brother Total active time : 232 minutes
Run the script once a month and get the number of minutes a student has been active on the pc.
PHP Code:
#!/bin/bash
###############################
#
# This script active.sh v0.5
# is created by FredrikN
# 2006-01-19
#
# fredrick@thegate.nu
#
# This script will calculate
# how many minutes a user has been
# using this pc
#
# The user stat will look something like:
#
# ---------------------------------------------
# User king Total active time : 43 minutes
# User media Total active time : 208 minutes
# User brother Total active time : 232 minutes
# ---------------------------------------------
#
#
# Installation as ROOT , se below:
#
# Step1.
# Append the following 10 lines to the file .bash_profile
# in users homedir
#
#
# if [ ! -s .active.log ] ;
# then
# `echo -n "Login:" >> .active.log ; date +%c' '%s >> .active.log`
# else
# if [ "`tail -n 1 .active.log | grep 'Login'`" == "" ] ;
# then
# `echo -n "Login:" >> .active.log ; date +%c' '%s >> .active.log`
# fi
# fi
#
#
#
#
# Step2.
# Append the following 8 lines to the file .bash_logout also
# in users homedir.
#
# if [ -s .active.log ] ;
# then
# OWNER="`ls -l .active.log | cut -d' ' -f 4`"
#
# if [ "`tail -n 1 .active.log | grep 'Logout'`" == "" ] && [ "`who | grep $OWNER | wc -l `" -lt 2 ] ;
# then
# `echo -n "Logout:" >> .active.log ; date +%c" "%s >> .active.log`
# fi
# fi
#
#
#
# Step3.
# Logout and login again.
# The file .active.log is now automatically created and should now look something like below
#
# -----------------------------------
# Login:Wed Jan 18 10:38:56 CET 2006
#
#
# Step4.
# You can now run this script and generate
# reports.
# Type ./active.sh to run this script
#
##############################
CALC=false
SUM=0
function calcTime
{
#Calc sec of last login by hour
let DIFF=$2-$1
let SUM=$SUM+$DIFF;
}
for dir in `ls /home/`;
do
if [ -s /home/$dir/.active.log ] ;
then
CALC=false
SUM=0
if [ `cat -n /home/$dir/.active.log | wc -l` -gt 1 ] ;
then
for i in `cat /home/$dir/.active.log | cut -d" " -f6`;
do
#Calc row by row
if [ $CALC == false ] ;
then
#Store login time
LOGIN=$i
CALC=true
else
LOGOUT=$i
calcTime $LOGIN $LOGOUT
CALC=false
fi
done;
#Check if there is a last line also, then the user is active
if [ "`tail -n 1 /home/$dir/.active.log | grep 'Login'`" != "" ] ;
then
#User is active, add the current login time as well
calcTime `tail -n 1 /home/$dir/.active.log | cut -d" " -f6` "`date +%s`"
fi
let VIEWMINUTES=$SUM/60;
echo "User $dir Total active time :" $VIEWMINUTES minutes
else
if [ `cat /home/$dir/.active.log | wc -l` -eq 0 ]
then
#If .active.log is empty
echo "No data to calculate"
else
#First time, eg only one row i .active.log
NOW=`cat /home/$dir/.active.log | cut -d" " -f6`;
calcTime $NOW "`date +%s`"
let VIEWMINUTES=$SUM/60;
echo "User $dir Total active time at this first login:" $VIEWMINUTES minutes
fi
fi
fi
done
The above script can be dl from
http://www.thegate.nu/tmp/active.txt