LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 08-17-2004, 03:52 PM   #1
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Mandriva 2008 Spring
Posts: 652

Rep: Reputation: 31
Limit time for a user per day


My wife is a bit concerned about how long her niece - who is staying with us - spends playing games on Linux. Is it possible to set up a user account for her which can only log in for x time a day ?

Last edited by davholla; 08-17-2004 at 03:59 PM.
 
Old 08-17-2004, 03:57 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
man logoutd
man porttime

:)


Cheers,
Tink
 
Old 08-18-2004, 06:21 AM   #3
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Mandriva 2008 Spring
Posts: 652

Original Poster
Rep: Reputation: 31
I tried that and my Suse 9.1 came back no page found (or whatever the exact thing is)
 
Old 08-18-2004, 06:28 AM   #4
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,176
Blog Entries: 4

Rep: Reputation: 430Reputation: 430Reputation: 430Reputation: 430Reputation: 430
I am away from my SuSE 9.1 system at the moment, but in YAST2 under account options (can't recall the exact name) there should be the option to allow/disallow the account at certain times of the day. Your other option, if that is not the case, is to set up a cron job - log her in and set it running - to force a logout after x amount of time.
 
Old 08-18-2004, 07:49 AM   #5
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Mandriva 2008 Spring
Posts: 652

Original Poster
Rep: Reputation: 31
I will try the cron job idea. I don't mind when she uses it just not too much !!
 
Old 08-18-2004, 03:48 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally posted by davholla
I tried that and my Suse 9.1 came back no page found (or whatever the exact thing is)
Odd - porttime & logoutd are part of the shadow suite
of password tools. What does SuSE use instead?


Cheers,
Tink
 
Old 08-20-2004, 08:27 AM   #7
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Mandriva 2008 Spring
Posts: 652

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by Tinkster
Odd - porttime & logoutd are part of the shadow suite
of password tools. What does SuSE use instead?


Cheers,
Tink
Sadly I don't know.

However I have written a python program that if run at start up by root should do this ( I will post it with comments here later).

How do I set it up so that when user x logs in root starts running this program ?
 
Old 08-20-2004, 04:39 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
A cron job that checks for logged in users
every minute?

Alternatively, give every user a .xsession/.xinitrc
file that's owned by root and that they can't over-
write, change or delete and that starts your script
via sudo.


Cheers,
Tink
 
Old 08-21-2004, 11:53 AM   #9
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Mandriva 2008 Spring
Posts: 652

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by Tinkster
A
Alternatively, give every user a .xsession/.xinitrc
file that's owned by root and that they can't over-
write, change or delete and that starts your script
via sudo.


Cheers,
Tink
How do I do that ?
In case anyone is interested here is the program.
It will work for a PC if you set it running on start up
Code:
#!/usr/bin/env python

def yesterortoday():
    #want to know if the machine has been used today or not
    #get today's date and a variable for today's date to store
    ctimeto = time.ctime()
    ctimetovar = ctimeto[0:11]
    #define the file name to save work if we want to change it
    filedatename = 'datelogin.txt'
    #debuging
    #print ctimetovar
    x = 0
    try:
        text_file = open(filedatename,"r")
        print filedatename, "does exist"
        cdatefromfile = text_file.readline()
        print "In the file ",cdatefromfile
        print "In the program", ctimetovar
        print "line 17"
        text_file.close()
        print "In line 17", cdatefromfile
        if cdatefromfile != ctimetovar:
            print "In line 18"
            writetofile(filedataname, ctimetovar)
            print "In line 23"
            x = 1
            print "In line 25"
    except:
        print filedatename, "does not exist"
        writetofile(filedatename, ctimetovar)
    print "in yesterortoday  x is", x
    return x

def writetofile(filename, ctimetovar):
    #store today's date in a file
    text_file = open(filename,"w")
    text_file.write(ctimetovar)
    text_file.close()

def timeinsecondstoday(x):
    #store the time used today in seconds
    filename = 'timeinseconds.txt'
    #if x is 0 then the PC has not been used today and so we don't care about the
    #contents of this file and we want to overwrite give a value of 1 for the
    #time the machine has been used
    if x == 1:
        x=str(x)
        writetofile(filename,x)
        print "Writing to file and removing deleting all data"
        incnumsecs(filename)
        #this means the PC has not been used today
    else:
        #print "x is not 0"
        incnumsecs(filename)
        #they have used it do not overwrite this
        
    #call a function that opens timeinseconds.txt and a) converts what is into
    #an int and adds to until a certain number of seconds reached

def shutdownmachine():
    try:
        os.system('halt')
    except:
        os.system('shutdown.exe')

def incnumsecs(filename):
    #get the number of seconds last time used today
    text_file = open(filename,"r")
    #timeinsecs = 0
    timeinsecs = text_file.readline()
    text_file.close()
    timeinsecs = int(timeinsecs)
    #debug line
    #print "The computer has been used for ", timeinsecs,"seconds today"
    #time limit is the amount of time before the program and PC shut down
    timelimit = 130 #time in seconds they should use the machine
    while timeinsecs < timelimit:
        time.sleep(20)
        timeinsecs = timeinsecs + 60
        #timeinsecsstr = str(timeinsecs)
        text_file = open(filename, "w")
        text_file.write(timeinsecs)
        text_file.close()
        print timeinsecs
    print timelimit, "has finished "
#if you just want to debug and you don't want the PC to shut down comment out
#the line below
#    shutdownmachine()
#main    
import time
import sys
import os

x= yesterortoday()
#print x
timeinsecondstoday(x)
 
Old 08-21-2004, 04:37 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally posted by davholla
Code:
A
Alternatively, give every user a .xsession/.xinitrc
file that's owned by root and that they can't over-
write, change or delete and that starts your script
via sudo.


Cheers,
Tink
How do I do that ?
In case anyone is interested here is the program.
It will work for a PC if you set it running on start up
Which bit do you not know?


Cheers,
Tink
 
Old 08-22-2004, 10:23 AM   #11
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Mandriva 2008 Spring
Posts: 652

Original Poster
Rep: Reputation: 31
Well I managed to change the .xinitrc file
:-
Code:
# Disable new Xcursor themes if none is specified resp. located in $HOME
# (use "unset XCURSOR_CORE" to enable them again later)
#if [ "x$XCURSOR_THEME" == "x" -a ! -d $HOME/.icons ]; then
#  export XCURSOR_CORE=true
#else
#  unset XCURSOR_CORE
#fi

# Prevent keyboard bouncing for Toshiba Notebooks
# Means, disable AccessX
test -r /etc/sysconfig/sax && source /etc/sysconfig/sax
if [ "x$KBD_BOUNCE_FIX" = "xyes" ]; then
        test -x /usr/X11R6/bin/xbounce && /usr/X11R6/bin/xbounce
fi

#
# Uncomment next line to activate asking for ssh passphrase
#
# ssh-add

#
# Add your own lines here...
#


# day planer deamon
# pland &

#
# finally start the window manager
#
exec $WINDOWMANAGER
python shutdownv2.py
# call failsafe
exit 0
But either a) I did this wrong so it does not call the python program
or b) the .xinitrc file is not called when someone logs in.
 
Old 08-22-2004, 03:14 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
It depends on how you start X / login whether the
system uses .xinitrc or .xsession. Using xdm or the
like will grab .xsession, startx will use .xinitrc. Try
renaming the file, and see again.

If the script is being started as that from the users
.xsession it will run with user-privileges. I'd suggest
you add a line for it for all users to /etc/sudoers and
start it via sudo from your script.


Cheers,
Tink

P.S.: Seems to me that trying to get a hold of
porttime for SuSE might have been faster ;)
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Allow a user to use gaim only at a certain time of the day Menestrel Linux - Security 5 07-04-2005 01:30 AM
ISO - 5 Day Download Time Limit rrrssssss Mandriva 3 03-15-2005 07:47 AM
Hoto limit the number of minutes a user may be loged on in a day? Mandrake 9 tmillard Linux - Software 1 04-13-2004 08:04 PM
first time linux user, frist day with mandrake9.1 on my system. Sabastian Linux - Software 34 06-20-2003 12:10 AM
first time linux user, frist day with mandrake9.1 on my system. Sabastian Linux - Newbie 4 06-18-2003 03:35 AM


All times are GMT -5. The time now is 02:19 AM.

Main Menu
Advertisement
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