LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices

Reply
 
Search this Thread
Old 01-06-2006, 03:38 AM   #1
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Rep: Reputation: 30
How to limit the account usage.


Hello everybody,
I have FC 4 and two kids, who are always seen playing games on computer.
Can I somehow limit their account usage to say one hour everyday.

Looks like a tall order. to me.
Any help ?

Thanks in advance.

-Prabhat Soni

Last edited by prabhatsoni; 01-06-2006 at 03:39 AM.
 
Old 01-06-2006, 08:12 AM   #2
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Rep: Reputation: 15
Hello

There might be many ways to implement this.

One way is to use a bash script and run it every minute, it's a small script so it's gentle to the CPU.

Place a file called .minutesToday.txt under each kids dir.
Make sure only root can modify the file.

Then run a script every minute that works like

PHP Code:
#!/bin/bash

#Check if kid is active
if [ "`who | grep kid`" != "" ]
then
   
if [ "`cat /home/kid/.minutesToday.txt`" -gt 60 ]
   
then
      
#kid has been active for 60min or more, kill all process 
      #that is started by kid
      
ps -Af grep "kid" awk '{print $2}' xargs kill -9
   
else
      
#inc minutes in .minutesToday.txt
      
DATA=`cat /home/kid/.minutesToday.txt`
      
let DATA=$DATA+1
      
echo $DATA > /home/kid/.minutesToday.txt
   fi
fi 
And don't forget to reset(with cron) the file by writing 0 in .minutesToday.txt every midnight or something.

This is one way to solve the problem, I'm sure better methods exists.

Last edited by FredrikN; 01-09-2006 at 07:54 AM.
 
Old 01-07-2006, 12:42 PM   #3
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Rep: Reputation: 15
So, did you solve the problem ?
 
Old 01-08-2006, 10:59 PM   #4
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
I was out of station for a few days so could not login.
I will check up and post the report in a day or two.

Thanks a lot


Prabhat Soni
 
Old 01-17-2006, 12:56 AM   #5
andygo
Member
 
Registered: May 2005
Location: Ukraine, Kiev
Distribution: Gentoo, Kubuntu
Posts: 112

Rep: Reputation: 15
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
 
Old 01-18-2006, 02:19 AM   #6
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Rep: Reputation: 15
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 [ -
/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

Last edited by FredrikN; 01-18-2006 at 06:06 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
limit cpu % usage for a process student04 Linux - General 15 03-18-2014 07:22 PM
limit usage? mifan Linux - Newbie 4 04-18-2004 06:05 AM
How can I limit the CPU usage of a PID? ideasman Linux - Software 1 04-01-2004 07:15 AM
account and email attachment limit red_phoenix Debian 2 09-16-2003 03:22 AM
How to Limit Runtime Resource Usage Skywings Programming 0 11-22-2001 07:45 PM


All times are GMT -5. The time now is 07:37 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration