LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 02:52 PM   #1
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Linux Mint 13 Maya
Posts: 729

Rep: Reputation: 32
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 02:59 PM.
 
Old 08-17-2004, 02:57 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
man logoutd
man porttime

:)


Cheers,
Tink
 
Old 08-18-2004, 05:21 AM   #3
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Linux Mint 13 Maya
Posts: 729

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

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
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, 06:49 AM   #5
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Linux Mint 13 Maya
Posts: 729

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

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 07:27 AM   #7
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Linux Mint 13 Maya
Posts: 729

Original Poster
Rep: Reputation: 32
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, 03:39 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 10:53 AM   #9
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Linux Mint 13 Maya
Posts: 729

Original Poster
Rep: Reputation: 32
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, 03:37 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 09:23 AM   #11
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Linux Mint 13 Maya
Posts: 729

Original Poster
Rep: Reputation: 32
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, 02:14 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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



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 12:30 AM
ISO - 5 Day Download Time Limit rrrssssss Mandriva 3 03-15-2005 06: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 07:04 PM
first time linux user, frist day with mandrake9.1 on my system. Sabastian Linux - Software 34 06-19-2003 11:10 PM
first time linux user, frist day with mandrake9.1 on my system. Sabastian Linux - Newbie 4 06-18-2003 02:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:17 PM.

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
Open Source Consulting | Domain Registration