0

I want to restrict the access to user accounts for employees to the working hour daily.

Monday to Friday (8:00-17:00)
Saturday (8:00-13:00)

How to do this?!

Command line and GUI apps are well accepted

3
  • 1
    Take a loot at a small script I wrote : pastebin.ubuntu.com/10944439 . I know it's very simplistic. The idea is to create a .desktop file to start this up on every graphical login. I don't want to post it as an answer, since this is custom thing and don't wanna get down voted, but check it out, and let me know what you think Apr 29, 2015 at 20:25
  • @Serg It's great, but it need some modifications in timing, Saturday work hours are not same as The rest of week days and also you have to pay attention for the Sunday(no work).
    – Maythux
    May 11, 2015 at 10:49
  • @Serg Modify it and post it as answer. I preferred these answers instead of apps
    – Maythux
    May 11, 2015 at 10:50

3 Answers 3

2

Here is the improved version of my original script I've linked in the comments. This script uses all the tools that come with ubuntu, namely at(for task scheduling) , date, and gnome-session-quit so no additional installation of software is necessary. This script can be called from ~/.config/autostart or /etc/xdg/autostart in a .desktop file.

date will determine current hour of the day as well as day of the week (number). Case structure then decides which parameter to give to logthemout function; the parameter is the clock-out hour of the day. For monday - friday it is 17:00, and for Saturday that's 13:00. logthemout function will in turn check if the current time is within working hours range (if statement with logical "or" ). If it is, the user will receive appropriate notification that they will be logged out at specific time. If the working hours are not within the range, the user will be logged out. Technically speaking, what is happening is that the user logs in, but the script logs them out right away. The shortcomings of this script is that the script depends on system time. If a user has ability to alter system time, they have ability to bypass the script. Otherwise, this should work.

#!/bin/bash
set -x

HOUR=$(date +%H)
DAYOFWEEK=$(date +%u)

function logthemout
{
    if [[ $HOUR -gt $1 || $HOUR -lt 8 ]]; then

        gnome-session-quit --no-prompt

    else 
        notify-send "AUTO-LOGOUT AT $1 pm"
        echo "gnome-session-quit --no-prompt" | at $1:00
    fi
}



case $DAYOFWEEK in
    1|2|3|4|5) logthemout 17;;
    6) logthemout 13;;
    7) gnome-session-quit --no-prompt ;;
esac

Clarification:

Typically if you want to run something on GUI login, you'd have to create something like /home/username/.config/autostart/mystartup-prog.desktop , which should have a format similar to this:

[Desktop Entry]
Type=Application
Name=<Name of application as displayed>
Exec=<command to execute>
Icon=<full path to icon>
Comment=<optinal comments>
X-GNOME-Autostart-enabled=true

If you have a lot of workers, this might be inefficient, so better way would be to have one such entry in /etc/xdg/autostart/mystartup-prog.desktop.

8
  • +1 for your effort and I'm gonna test it and return
    – Maythux
    May 13, 2015 at 16:36
  • DO you manage how to make it as a daemon or just run it every day?
    – Maythux
    May 13, 2015 at 16:37
  • @NewUSer give me a moment, I will update my answer to clarify it a little bit May 13, 2015 at 16:44
  • @NewUSer OK, added more info. Basically it will run every time somebody logs in May 13, 2015 at 17:13
  • Good then you make it a startup application. What could we do to prevent killing it
    – Maythux
    May 13, 2015 at 17:16
2

Since you're an experienced user, I suggest you use pam_time:

The pam_time PAM module does not authenticate the user, but instead it restricts access to a system and or specific applications at various times of the day and on specific days or over various terminal lines. This module can be configured to deny access to (individual) users based on their name, the time of day, the day of week, the service they are applying for and their terminal from which they are making their request.

0

I think TimeKpr will do the job. Here's the link https://launchpad.net/timekpr

2
  • The latest release date is 2009-12-11.
    – A.B.
    Apr 30, 2015 at 8:30
  • Even though it's outdated it still works great
    – user393215
    Apr 30, 2015 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .