Page 1 of 1

Time limit on guest account - help needed [solved]

Posted: Sat Sep 17, 2011 8:11 pm
by MintLover4Ever
Hi,
I really need help with the creation of a script to allow access for timed intervals of 30 mins on a Guest account and since I am a complete beginner with scripting I hope the community can lend a generous hand with the development of said script.
Here's the story, I have recently refurbished a computer and installed Linux Mint 11 with very few noticeable issues. I created a Guest account for use by my clients to check email or edit some documents but the only problem that remains is the lack of a time limitation to prevent unnecessary extended use. I've Googled my brains out trying to find a viable option but to no avail, the only one that has what I want is http://u-scripts.blogspot.com/2010/03/a ... -kids.html the only dependency is on Conky which is NOT compatible with the new linux mint 11. Here are the minimal parameters for what I'm looking for:

-a simple script that is engaged at login of Guest account
-script logs off only the Guest account after 30 minutes of use
-Does not affect the admin account which will also be engaged for extraneous purposes behind the scenes
-blocks re-login for 5 min (if possible)

For a more advanced version my only hope is for a timer that shows the amount of remaining time.

Re: Time limit on guest account - help needed

Posted: Sun Sep 18, 2011 3:14 am
by Oscar799
Split from another thread and title edited

Re: Time limit on guest account - help needed

Posted: Mon Sep 19, 2011 5:02 am
by Pilosopong Tasyo
How about a rough algorithm instead, just to give you a head start?

Code: Select all

#!/bin/sh

# Some useful variables
TIME_NOW = current time expressed in seconds
END_TIME = computed ending time (also expressed in seconds)

# Countdown loop
while TIME_NOW < END_TIME
do
  # Display a reminder once per minute
  REMINDER_FLAG = (END_TIME-TIME_NOW) modulus 60
  if REMINDER_FLAG = 0
  then
    REMAINING_TIME = (END_TIME-TIME_NOW) / 60
    display REMAINING_TIME on screen
  fi

  # Update the current time
  TIME_NOW = current time (expressed in seconds)
  sleep 1 # Don't hog the CPU!
done

# Time is up!
force logout user

# EOF
Then you can set the script to run upon login of the guest account (via Startup Applications). The algorithm satisfies all your requirements (including remaining time notification) except the last one (blocks relogin for 5 minutes -- perhaps a future exercise?). Also note the algorithm doesn't take into consideration if the guest user logs out of the account before his/her alloted time is up. No need for conky either, though you might need to download a small package in order to display on-screen notifications.

Try to understand the logic of the above algorithm. It will help you tremendously if you get the idea how it works. Look up the following for hints as well:
  • date
    expr
    notify-send
    pkill / gnome-session-save
HTH.