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
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
.
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.
I think TimeKpr will do the job. Here's the link https://launchpad.net/timekpr
.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