Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 ?
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.
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.
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)
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
# 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.
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 ;)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.