如何限制孩子的计算时间?

访问我们的计算机(不仅仅是互联网)需要限制我的孩子的帐户(7,8),直到他们年龄足够自己管理这个。 在此之前,我们需要能够定义以下内容:

  • 计算正常的时间(例如下午5点到9点)
  • 计算不好的一周中的日子(例如星期一到星期五)
  • 每天允许的时间(例如2小时)

在11.10中,以前用于完成工作的以下所有内容都不再起作用:

  • Timekpr :对于> 11.10,通过ppa不再提供。
  • Timeoutd :命令行替代,但从11.10中删除了存储库
  • Gnome Nanny :看起来很棒但反复崩溃迫使重启X-server。 所以我们暂时不能使用或推荐这个程序。

还有其他选择吗?

锁屏定时器

systray.gif

创建自己的屏幕锁定计时器而不是第三方应用程序

虽然有第三方应用程序可以执行此操作,但您可以创建自己的应用程序。 步骤摘要:

  • 使用gedit创建脚本lock-screen-timer
  • 将此窗口中的代码复制并粘贴到lock-screen-timer
  • lock-screen-timer标记为可执行文件
  • 测试一下!
  • 配置Nautilus以执行bash脚本
  • 创建桌面快捷方式链接
  • 监控剩余时间

使用gedit创建脚本lock-screen-timer

使用Ctrl + Alt + T打开Terminal并键入:

 gedit lock-screen-timer 

将代码从下面的窗口复制并粘贴到lock-screen-timer

切换回此屏幕并通过突出显示并按Ctrl + C复制以下代码:

 #!/bin/bash # NAME: lock-screen-timer # PATH: $HOME/bin # DESC: Lock screen in x minutes # CALL: Place on Desktop or call from Terminal with "lock-screen-timer 99" # DATE: Created Nov 19, 2016. Last revision Mar 22, 2018. # UPDT: Updated to support WSL (Windows Subsystem for Linux) # Remove hotplugtv. Replace ogg with paplay. # NOTE: Time defaults to 30 minutes. # If previous version is sleeping it is killed. # Zenity is used to pop up entry box to get number of minutes. # If zenity is closed with X or Cancel, no screen lock timer is launched. # Pending lock warning displayed on-screen at set intervals. # Write time remaining to ~/.lock-screen-timer-remaining MINUTES="$1" # Optional parameter 1 when invoked from terminal. # if no parameters set default MINUTES to 30 if [ $# == 0 ]; then MINUTES=30 fi DEFAULT="$MINUTES" # When looping, minutes count down to zero. Save deafult for subsequent timers. # Check if lock screen timer already running pID=$(pgrep -f "${0##*/}") # All PIDs matching lock-screen-timer name PREVIOUS=$(echo "$pID" | grep -v ^"$$") # Strip out this running copy ($$$) if [ "$PREVIOUS" != "" ]; then kill "$PREVIOUS" rm ~/.lock-screen-timer-remaining zenity --info --title="Lock screen timer already running" --text="Previous lock screen timer has been terminated." fi # Running under WSL (Windows Subsystem for Linux)? if cat /proc/version | grep Microsoft; then WSL_running=true else WSL_running=false fi while true ; do # loop until cancel # Get number of minutes until lock from user MINUTES=$(zenity --entry --title="Lock screen timer" --text="Set number of minutes until lock" --entry-text="$DEFAULT") RESULT=$? # Zenity return code if [ $RESULT != 0 ]; then break ; # break out of timer lock screen loop and end this script. fi DEFAULT="$MINUTES" # Save deafult for subsequent timers. if [[ $MINUTES == 0 ]] || [[ $MINUTES == "" ]]; then break ; # zero minutes considered cancel. fi # Loop for X minutes, testing each minute for alert message. (( ++MINUTES )) while (( --MINUTES > 0 )); do case $MINUTES in 1|2|3|5|10|15|30|45|60|120|480|960|1920) notify-send --urgency=critical --icon=/usr/share/icons/gnome/256x256/status/appointment-soon.png "Locking screen in ""$MINUTES"" minute(s)." ; if [[ $WSL_running == true ]]; then powershell.exe -c '(New-Object Media.SoundPlayer "C:\Windows\Media\notify.wav").PlaySync();' else paplay /usr/share/sounds/freedesktop/stereo/complete.oga ; fi ;; esac; # Record number of minutes remaining to file other processes can read. echo "$MINUTES Minutes" > ~/.lock-screen-timer-remaining sleep 60 done rm ~/.lock-screen-timer-remaining # Remove work file others can see our progress with if [[ $WSL_running == true ]]; then # Call lock screen for Windows 10 rundll32.exe user32.dll,LockWorkStation else # Call screen saver lock for Unbuntu versions > 14.04. dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock fi done # End of while loop getting minutes to next lock screen exit 0 # Closed dialog box or "Cancel" selected. 

然后切换回空的gedit窗口并使用Ctrl + V粘贴代码。 保存文件并退出编辑器返回到命令提示符。

lock-screen-timer标记为可执行文件

现在我们需要输入以下命令使脚本可执行:

 chmod +x lock-screen-timer 

测试吧!

在从GUI调用脚本之前,我们将从终端调用它,以便我们可以看到是否显示任何错误消息:

 ~/lock-screen-timer 

系统会提示您输入分钟数:

锁屏定时器

设置所需的分钟数,然后单击“确定”以启动计时器。 当剩余15分钟,10分钟,5分钟,3分钟,2分钟和1分钟时,会听到系统声音并出现消息气泡,告知屏幕何时被锁定。 屏幕锁定后,您需要输入密码才能解锁屏幕。

配置Nautilus以执行bash脚本

Nautilus定义当我们在文件显示窗口或桌面上的链接上双击可执行脚本时会发生什么。 正常行为是使用gedit编辑脚本。 我们想要改变这种行为,以便它被执行。

启动Nautilus并导航到包含lock-screen-timer目录。 左键单击一次以使其聚焦。 将鼠标hover在顶部菜单栏上,直到出现“文件编辑…”菜单,使用:

  1. 单击“ Edit下拉菜单
  2. 单击Properties选项
  3. 单击Behavior选项卡
  4. 观察Executable Text Files下的单选选项按钮
  5. 检查单选按钮Run executable text files when they are opened

创建桌面快捷方式链接

从上一节开始, lock-screen-timer仍然具有焦点。 如果没有,请导航到脚本并左键单击一次以使其获得焦点。 然后使用:

  • 右键单击该文件,将出现上下文菜单选项。
  • 从菜单中选择Make Link
  • 出现一个名为Link to lock-screen-timer新图标。
  • 左键单击新图标并将其从Nautilus拖到桌面。

现在,您可以双击桌面快捷方式链接并运行脚本。 将出现一个对话框以获取分钟数。 两个按钮显示取消确定 。 如果单击X关闭窗口,则与选择取消相同。

计时器运行后再次双击它,第一个正在运行的副本被“杀死”。 您现在可以开始新的scren锁倒计时或单击取消进行无倒计时。

显示系统托盘/通知区域中剩余的时间

当锁定屏幕计时器正在运行时,它会记录文件剩余多少分钟~/.lock-screen-timer-remaining 。 您可以使用watch命令查看此文件,或将其显示在Ubuntu的系统托盘/应用程序指示条上,如本答案顶部所示。 要显示通知区域中剩余的时间,请按照此问答中的说明进行操作:( 可以在系统托盘中显示BASH作为应用程序指示器吗? )。

Ubuntu <= 11.10用户按照Ubuntu用户指南> = 11.10阅读底页通知:

是的,所有这些程序都已过时,所有问题都在这里得到解答,并与您的父母控制好看……

当我们谈论强制用户注销时,我们真正谈论的是对系统访问或服务的帐户实施时间限制。 我发现实现时间限制的最简单方法是使用名为Linux-PAM的插件模块。

可插拔认证模块(PAM)是一种用于认证用户的机制。 具体来说,我们将使用pam_time模块来控制用户对服务的定时访问。

使用pam_time模块,我们可以在一天中的不同时间以及特定日期或通过各种终端线设置对系统和/或特定应用程序的访问限制。 根据配置,您可以使用此模块根据个人用户的姓名,时间,星期几,他们申请的服务以及他们发出请求的终端来拒绝访问个人用户。

使用pam_time ,必须使用换行符终止/etc/security/time.conf文件中每一行(或规则)的语法。 您可以使用井号[#]对每一行进行注释,系统将在新行之前忽略该文本。

以下是规则的语法:

服务; ttys文件;用户;倍

 The first field — services — is a logic list of PAM service names. The second field — tty — is a logic list of terminal names. The third field — users — is a logic list of users or a netgroup of users. The fourth field — times — indicates the applicable times. 

以下是一组典型规则的示例:

 login ; * ; !bobby ; MoTuWeThFr0800-2000 login ; * ; !root ; !Al0000-2400 http ; * ; !bobby ; MoTuWeThFr0800-2000 http ; * ; !root; !Al0000-2400 

这些规则限制用户bobby在0800和2000之间登录,并且他们还限制在这些时间内访问Internet。 Root可以随时登录并在任何时候浏览Internet。

注意:系统将这些规则的错误记录为syslog(3)。


使用Ubuntu Linux,可以为计算机分配时间限制,以防止一个或多个用户连接到您的系统。 例如,根据时间限制,您可以限制为您的孩子访问计算机(简而言之是一种家长控制) ,甚至可以在特定时间内保护与服务器的连接。

手动配置

了解你会做什么

在本教程中,我们将使用PAM(可插入身份validation模块,英语可插入身份validation模块)。 它允许您在连接时控制用户身份validation。 然后,我们将使用安全配置文件来定义允许的登录时间。 这些操作可以在任何版本的Ubuntu上执行,并且只需要一个简单的文本编辑器(vim,emacs,nano,gedit,kate,仅举几例)。 通过PAM模块启用限制时间

首先,首先转到/etc/pam.d/ ,其中包含所有可配置服务:

 $ Ls /etc/pam.d/ atd common-account common-session gdm login ppp sudo chfn common-auth cron gdm-autologin Other samba chsh common-cupsys gnome-screensaver password passwd su 

如果我们想阻止与计算机的连接,我们将不得不更改gdm服务。 编辑文件gdm并添加这行代码(在文件末尾):

 account required pam_time.so 

GDM是登录屏幕分发Ubuntu,Edubuntu和Xubuntu。 对于使用KDE的Kubuntu,调用kdm服务,它将是它将打开的文件。 你完成配置PAM了! 这样可以控制此服务的小时数。

如果您有服务器,则可能没有GUI。 在这种情况下,未安装GDM / KDM,并且不会阻止连接。 要阻止与TTY的连接,必须修改同一文件的登录名,并添加与先前确认的代码行相同的代码行。 此操作也适用于已安装GUI并希望阻止访问登录屏幕和终端的人员。

配置访问时间

既然PAM服务已经激活,我们只需要配置访问时间。 打开/etc/security 。 有几个配置文件可用:

 $ Ls /etc/security/ access.conf namespace.conf pam_env.conf group.conf namespace.init time.conf limits.conf opasswd time.conf.bak 

编辑文件time.conf 。 一些解释和例子(英文)介绍了。 要设置访问计划,请复制并粘贴以下代码行(在文件的末尾,一如既往):

 *;*;user;scheduler 

而不是用户字段,输入要阻止的登录帐户。

如果要阻止多个用户,请连续输入他们的登录名,以|分隔 运营商。 例如,如果我要冻结Patrick,John和Emily的帐户:

 *;*;Patrick|jean|emilie;scheduler 

通过利弊,如果你想阻止所有用户访问系统,特别是一个用户,请使用! 在有关人员之前。 例如,如果我想要拒绝所有用户访问计算机,除了Nicolas和Xavier:

 Nicolas *;*;!|xavier;scheduler 

现在转到现场区域。 在此字段中,可以选择日期和小时进行连接。 您必须首先使用以下缩写指定星期几:

 Mo : Monday Fr : Friday Wd : Sa/Su Tu : Tuesday Sa : Saturday wk : Mo/Tu/We/Th/Fr We : Wenesday Su : Sunday Th : Thursday Al : All Days 

注意不要混淆Wk和Wd的缩写是误导性的! 在互联网上特别缺乏识别:您可以轻松找到相互矛盾的信息!

然后,我们指定截止日期。 这些格式应为24H,由4位数组成。 例如,为了限制下午3:17到下午6:34,我们写道:1517-1834。 为了让玛丽只在星期二,从下午3:17到下午6:34连接,我们得到结果:

 *;*;marie;Tu1517-1834 

超出这些时间的连接将被禁止。 对于用户,可以使用运算符| 和! 多次指示(然后表示允许所有登录时间,除了要显示的那些)。

代码行开头的两颗星(通配符)分别是tty服务字段。 由于您要阻止对系统的所有访问,因此无需指定要阻止的服务或tty。 但是,如果要阻止使用特定服务,只需将其指定为以下示例:

 login;tty1|tty4|tty5;marie;!Wd0000-2400 

因此,用户结婚不能在周末期间连接到TTY,4和5。

限制时间表的一些例子

mathilde允许每天从下午1:20到下午3:20以及下午4:00到晚上8:30连接:

 *;*;mathilde;Al1320-1520|Al1600-2030 

允许Stone,Frank和Florian在工作日的下午2:00至下午6:45以及周末的下午2:00至10:15连接:

 *;*;Stone|franck|florian;Wk1400-1845|Wd1400-2215 

Olive永远不允许连接。 杰西卡可以在星期三下午1点到4点登录:

 *;*;olivier;!Al0000-2400 *;*;jessica;We1300-1600 

2个不同的行,每个用户两个不同的时间会话到期

当会话到期时(超过用户已连接的时间),PAM可以到达用户。 虽然mathilde在允许的时间内连接,但完全可以自由地超过这些时间! 为此,我们将使用一个新程序:’cron’。 该应用程序每隔一段时间执行一次命令。 在我们的例子中,我们将使用命令’skill-KILL-u’在会话到期时断开用户连接。 处理非常简单。 只需编辑文件’/ etc / crontab’即可。 然后添加以下代码行:

 Minute Hour Day * * (s) root skill -KILL -u User 

和以前一样,替换Minute字段的时间表和所需的时间。 然后在(s)天被禁止的日期填写,或者只需键入星号(*)即表示一周中的所有日期。 最后,更改登录帐户使用的字段将被阻止,瞧!

几天没有注意到与cron工作相同的方式! 以下是此程序使用的缩写列表:

 mon : monday fri : friday tue : tuesday sat : saturday wed : wednesady sun : sunday thu : thursday * : all hours 

cron作业的一些示例(上一节中的时间示例)

杰西卡可以在星期三下午1点到4点登录

– >断开:周二下午4:00。

 00 16 * root * wed skill -KILL -u jessica 

mathilde允许每天从下午1:20到下午3:20以及下午4:00到晚上8:30连接。

– >断开连接:每日,美国东部时间晚上8:30至下午3:20。

 20 15 * * * root skill -KILL -u mathilde 30 20 * * * root skill -KILL -u mathilde 

允许Stone,Frank和Florian在工作日的下午2:00至下午6:45以及周末的下午2:00至10:15连接

– >断开连接(1):周一,周二,周三,周四和周五,18:45。 – >断开连接(2):周六和周日晚上10:15。

 45 18 * * mon,tue,wed,thu,fri root skill -KILL -u stone && skill -KILL -u franck && skill -KILL -u florian 15 22 * * sat,sun root skill -KILL -u stone && skill -KILL -u franck && skill -KILL -u florian 

命令技能-KILL-u断开用户与GUI以及TTY的连接。 它完全适用于服务器管理员。 但是,此命令是立即执行的,并且将在不事先通知的情况下断开连接。 因此,最好防止安装此设备的计算机或网络用户!

可以防止用户在时间帧结束前几分钟由cron启动wall命令,这将显示在所有用户的终端中。

 40 18 * * Mon,Tue,wed,thu,fri root echo "end of session in 5 minutes" | wall 

为了防止用户从GUI中取代wall命令,可以在libnotify-bin包中使用notify-send 安装X.

 40 18 * * Mon,Tue,wed,thu,fri stone DISPLAY=:0 notify-send "end of session in 5 minutes" 

Ubuntu 11.10用户

我已经看到用户有Pam的问题,我看到了很多关于这个的错误,为什么是原因??? 是如此简单Ubuntu 11.10不再支持GDM新显示管理器是lightGDM问题是如下所示存储此指令account required pam_time.so我想是在/etc/pam.d/lightdm/etc/pam.d/lightdm-autologin但是如何???

所以对于你周围可以检查这2个LightGdm日志文件:

  • /var/log/lightdm/lightdm.log
  • /var/log/lightdm/x-0.log

或者在调试模式下运行LightGdm:

LightDM – 调试

或报告错误:

ubuntu-bug lightdm

我在这里报告Bug ,所以交叉你的手指等待….

TimeKpr

我想它拥有你需要的一切。 限制每个用户每天的访问时间,轻松配置配置,绕过一天的abitlity,添加一些“奖励时间”,通知用户的剩余时间等。

项目页面在这里 。 他们还有ubuntu的PPA,您可以将其添加到您的软件源: deb http://ppa.launchpad.net/timekpr-maintainers/ppa/ubuntu lucid main 。 并通过软件中心或CLI sudo apt-get install timekprsudo apt-get install timekpr

Timekpr

可以在运行LightDM的11.10中使用,通过将以下行添加到/etc/pam.d/lightdm来为用户设置限制

 account required pam_time.so 

我们可能需要删除libpam-smbpass以启用用户切换,直到修复了错误#835310 。

应用程序窗口中定义的所有限制都按照timekpr GUI中的定义工作。

要在Unity中显示timekpr-client图标,我们需要在Unity面板设置'timekpr' 列入白名单 ,此外我们还需要将Unity添加到/etc/xdg/autostart/timekpr-client.desktop的以下行:

 OnlyShowIn=GNOME;XFCE;KDE;Unity; 

要开始倒计时,我们可能必须启动timekpr守护进程

 /etc/init.d/timekpr start 

14.04:

Eduards Bezverhijs在他的ppa:mjasnik/ppa为Ubuntu 14.04发布了更新的timekpr版本/分支。

如果您处于某种状态,自动注销非常令人沮丧。 它很暴力,很残酷,很粗鲁。 无论你多大年纪都没关系。 当你只是计算机上瘾时,这是一回事,当你追踪时间并在你设法点击提交按钮或保存文档之前5秒被踢出时,这是非常不同的。 我建议你考虑使用自动提醒而不是自动提示。 这将教会你的孩子互相尊重,并允许彼此自愿使用电脑。

甚至还有一个更轻松的选择。 首先跟踪每个孩子使用计算机所花费的时间,并使收集的数据可供所有人使用,以便他们可以看到它。 当我在一个充满成人的办公室担任网络管理员时,这个非常简单的事情(应用于互联网带宽花费)已经挽救了我的生命。 关于每台计算机的带宽使用情况的公开统计数据(只是字节数,而不是像访问网站列表那样去除匿名信息等)将情况从“我 – 邪恶贪婪的管理员对他们 – 可怜的滥用办公室用户”转变为“男人,你下载的次数比我多5倍,那太糟糕了!“ “对不起,我确实下载了,我在午休期间看了很多youtube,不会再以这个速度做了” – 我只是被排除在对抗场景之外。

我也有这个问题。 所以我写了一个kidtimer脚本,它允许你定义使用时间和总数。 该项目可以在Github的以下位置找到:

这是如何安装和使用它:

  1. 将代码复制并粘贴到名为kidtimer.install的文件中。

     #!/bin/bash # Restrict kids computer access to specific hours and total time. # By: Michael Groves - grover66_at_gmail_dot_com #variables basedir="/usr/local/kidtimer" configdir="/etc/kidtimer" Cdate=`/bin/date | awk '{ print $2" "$3 }'` TUI=0 HOUR=`/bin/date +%H` DOW=`/bin/date +%u` WEEKEND="no" [ "$DOW" == "6" ] && WEEKEND="yes" [ "$DOW" == "7" ] && WEEKEND="yes" #arguments [ $# -eq 0 ] && TUI=1 [ $# -eq 1 ] && COMMAND=$1 [ $# -eq 2 ] && COMMAND=$1 && KID=$2 [ $# -eq 3 ] && COMMAND=$1 && KID=$2 && Time=$3 ################# Subroutines ################## ################################################ go_check_install () { if [ ! -e $basedir ]; then go_initialize fi } go_initialize () { /bin/mkdir -p $basedir/time /bin/mkdir -p $basedir/schedule /bin/cp $0 /usr/local/bin/kidtimer && chmod +x /usr/local/bin/kidtimer echo "0 * * * * root /usr/local/bin/kidtimer hourly" > /etc/cron.d/kidtimer echo "0 0 * * * root /usr/local/bin/kidtimer daily" >> /etc/cron.d/kidtimer echo "* * * * * root /usr/local/bin/kidtimer check" >> /etc/cron.d/kidtimer echo "@reboot root /usr/local/bin/kidtimer daily" >> /etc/cron.d/kidtimer echo "@reboot root /usr/local/bin/kidtimer hourly" >> /etc/cron.d/kidtimer /bin/mkdir $configdir /usr/bin/touch $configdir/kid.list go_create_message_files echo "Kidtimer is now installed. Run /usr/local/bin/kidtimer to configure." } go_create_message_files () { cat << EOF > $basedir/send5.sh #!/bin/bash Name=\$1 /bin/su -s /bin/bash -c 'DISPLAY=:0 /usr/bin/notify-send -i \ /usr/share/pixmaps/gnome-set-time.png "ALERT" \ "You will be logged out in 5 minutes."' \$Name EOF chmod +x $basedir/send5.sh cat << EOF > $basedir/send4.sh #!/bin/bash Name=\$1 /bin/su -s /bin/bash -c 'DISPLAY=:0 /usr/bin/notify-send -i \ /usr/share/pixmaps/gnome-set-time.png "ALERT" \ "You will be logged out in 4 minutes."' \$Name EOF chmod +x $basedir/send4.sh cat << EOF > $basedir/send3.sh #!/bin/bash Name=\$1 /bin/su -s /bin/bash -c 'DISPLAY=:0 /usr/bin/notify-send -i \ /usr/share/pixmaps/gnome-set-time.png "ALERT" \ "You will be logged out in 3 minutes."' \$Name EOF chmod +x $basedir/send3.sh cat << EOF > $basedir/send2.sh #!/bin/bash Name=$1 /bin/su -s /bin/bash -c 'DISPLAY=:0 /usr/bin/notify-send -i \ /usr/share/pixmaps/gnome-set-time.png "ALERT" \ "You will be logged out in 2 minutes."' \$Name EOF chmod +x $basedir/send2.sh cat << EOF > $basedir/send1.sh #!/bin/bash Name=\$1 /bin/su -s /bin/bash -c 'DISPLAY=:0 /usr/bin/notify-send -i \ /usr/share/pixmaps/gnome-set-time.png "ALERT" \ "You will be logged out in 1 minute."' \$Name EOF chmod +x $basedir/send1.sh cat << EOF > $basedir/logout.sh #!/bin/bash Name=\$1 /usr/bin/pkill -KILL -u \$Name rm -rf /tmp/kidtimer.shutdown.\$Name EOF chmod +x $basedir/logout.sh cat << EOF > $basedir/schedule/blank #hour weekday weekend (y/n) 00 nn 01 nn 02 nn 03 nn 04 nn 05 nn 06 nn 07 nn 08 yy 09 yy 10 yy 11 yy 12 yy 13 yy 14 yy 15 yy 16 yy 17 yy 18 yy 19 yy 20 nn 21 nn 22 nn 23 nn #minutes weekday weekend MAX 120 240 EOF } go_check () { for I in `cat $configdir/kid.list`; do /usr/bin/users | grep -q $I if [ $? -eq 0 ]; then if [ -e $basedir/time/$I.ttl ]; then C=`cat $basedir/time/$I.ttl` C=$((C + 1)) echo $C > $basedir/time/$I.ttl else echo 1 > $basedir/time/$I.ttl C=1 fi else go_clean_jobs $I exit 0 fi # check total time. W="no" [ $DOW -eq 6 ] && W="yes" [ $DOW -eq 7 ] && W="yes" [ "$W" == "no" ] && TIME_LIMIT=`cat $basedir/schedule/$I | grep ^MAX | awk '{ print $2 }'` [ "$W" == "yes" ] && TIME_LIMIT=`cat $basedir/schedule/$I | grep ^MAX | awk '{ print $3 }'` if [ $C -ge $TIME_LIMIT ]; then if [ ! -e /tmp/kidtimer.shutdown.$I ]; then /usr/bin/passwd $I -l go_logout $I fi fi done } go_clean_jobs () { K=$1 for I in `/usr/bin/atq | awk '{ print $1 }' | sort`; do /usr/bin/at -c $I | grep kidtimer | grep -q $K [ $? -eq 0 ] && /usr/bin/at -d $I done [ -e /tmp/kidtimer.shutdown.$K ] && rm -rf /tmp/kidtimer.shutdown.$K } go_daily () { for I in `cat $configdir/kid.list`; do ls -l $basedir/time/$I.ttl | grep -q "$Cdate" if [ ! $? -eq 0 ]; then echo "0" > $basedir/time/$I.ttl fi done } go_hourly () { if [ -s $configdir/kid.list ]; then for I in `cat $configdir/kid.list`; do if [ -e $basedir/schedule/$I ]; then [ "$WEEKEND" == "no" ] && TL=`cat $basedir/schedule/$I | grep ^MAX | awk '{ print $2 }'` [ "$WEEKEND" == "yes" ] && TL=`cat $basedir/schedule/$I | grep ^MAX | awk '{ print $3 }'` [ -e $basedir/time/$I.ttl ] && C=`cat $basedir/time/$I.ttl` [ $C -ge $TL ] && /usr/bin/passwd $I -l && exit 0 [ "$WEEKEND" == "no" ] && R=`grep ^$HOUR $basedir/schedule/$I | awk '{ print $2 }'` [ "$WEEKEND" == "yes" ] && R=`grep ^$HOUR $basedir/schedule/$I | awk '{ print $3 }'` if [ "$R" == "y" ]; then /usr/bin/passwd $I -u else /usr/bin/passwd $I -l /usr/bin/users | grep -q $I && /usr/local/bin/kidtimer shutdown $I fi fi done fi } go_logout () { K=$1 echo "$basedir/send5.sh $K" | at now + 1 minutes echo "$basedir/send4.sh $K" | at now + 2 minutes echo "$basedir/send3.sh $K" | at now + 3 minutes echo "$basedir/send2.sh $K" | at now + 4 minutes echo "$basedir/send1.sh $K" | at now + 5 minutes echo "$basedir/logout.sh $K" | at now + 6 minutes touch /tmp/kidtimer.shutdown.$K } go_addtime () { U=$KID A=$Time if [ "$KID" == "reset" ]; then echo "0" > $basedir/time/$U.ttl echo "Done." exit 0 elif [ "$KID" == "" ]; then echo "Error." echo "Syntax: addtime  " exit 1 else C=`cat $basedir/time/$KID.ttl` C=$((C - Time)) echo $C > $basedir/time/$KID.ttl echo "New total minutes is "$C"." echo "Done." fi /usr/bin/passwd $KID -u } go_tui () { go_command_list echo -n "Choose: "; read -e X case "$X" in 1) go_setup_user ;; 2) go_modify_user ;; 3) go_remove_user ;; 4) go_list_users ;; 5) exit 0 ;; esac go_tui } go_command_list () { echo echo "1) Setup user limits." echo "2) Modify user limits." echo "3) Remove user limits." echo "4) List configured users." echo "5) Quit." echo } go_list_users () { echo echo "Users configured for kidtimer:" if [ -s $configdir/kid.list ]; then cat $configdir/kid.list else echo "No configured users." fi } go_setup_user () { echo echo -n "Username: "; read -e U /usr/bin/id $U > /dev/null 2>&1 if [ $? -eq 0 ]; then /bin/cp $basedir/schedule/blank $basedir/schedule/$U echo "0" > $basedir/time/$U.ttl echo $U >> $configdir/kid.list echo "Done." echo echo -n "Modify limits now ?(y/n): "; read -e M if [ "$M" == "y" ]; then if [ -e /usr/bin/nano ]; then /usr/bin/nano $basedir/schedule/$U echo "Done." else /usr/bin/vi $basedir/schedule/$U echo "Done." fi fi else echo "Error. User does not exist. Please create user using the useradd command first." fi } go_modify_user () { echo echo -n "Username: "; read -e U grep -q ^$U $configdir/kid.list if [ $? -eq 0 ]; then if [ -e /usr/bin/nano ]; then /usr/bin/nano $basedir/schedule/$U echo "Done." else /usr/bin/vi $basedir/schedule/$U echo "Done." fi else echo "Error. User not setup. Please setup user first." fi } go_remove_user () { echo echo -n "Username: "; read -e U grep -q ^$U $configdir/kid.list if [ $? -eq 0 ]; then grep -v ^$U $configdir/kid.list > /tmp/kidtimer.tmp cat /tmp/kidtimer.tmp > $configdir/kid.list echo "Done." else echo "Error. User is not setup." fi } go_help () { echo echo "Commands:" echo "--------------------------------------------------------------------------------" echo "addtime   ... Increases allowed time for the day." echo "logout  ... Starts logout sequence for user." echo "hourly ... Enables/disables user access based on the schedule." echo "daily ... Resets time for the new day." echo "help ... This list." echo "--------------------------------------------------------------------------------" } ###################### Code #################### ################################################ go_check_install [ $TUI -eq 1 ] && go_tui case "$COMMAND" in addtime) go_addtime ;; logout) go_logout $KID ;; initialize) go_initialize ;; hourly) go_hourly ;; daily) go_daily ;; check) go_check ;; -h) go_help ;; help) go_help ;; esac exit 0 
  2. 执行它:

     sudo ./kidtimer.install 
  3. 运行:

     sudo kidtimer 
  4. 设置现有用户帐户。

  5. 完成。

求助:

 sudo kidtimer help 

为用户的帐户添加时间(仅限当天):

 sudo kidtimer addtime user minutes 

特征:

  • 工作日和周末都允许您的孩子在一天中的特定时段访问计算机。
  • 设置工作日和周末的最长时间。

关键文件:

 /etc/kidtimer/kid.list /etc/cron.d/kidtimer /usr/local/kidtimer/schedule/ /usr/local/kidtimer/time/.ttl /usr/local/bin/kidtimer 

Cronjobs:

  • 检查每分钟以查看用户是否已登录。如果是,则增加总时间。 如果达到最大时间,则禁用帐户并开始注销序列(总共5分钟)。
  • 每小时检查一次,看是否允许用户登录。 如果是,请启用帐户。
  • 午夜时分,重置时间。

注意:

应用程序使用notify-send来警告用户时间不多了。 当时间用完时,所有用户进程都会终止,因此请准备用户。

timekpr – 该程序将跟踪和控制用户帐户的计算机使用情况。 您可以根据定时访问持续时间限制其日常使用情况,并配置可以或无法登录的时段。通过此应用程序,管理员可以限制帐户登录持续时间或帐户访问时间。 该应用程序用作父母时间控件,对于想要限制子访问时间的父母非常有用。

 Even Nedberg proposed the following answer: Just started copying into the 11.10 version for the PPA. Should finish in a few minutes. 

您可以通过将ppa:timekpr-maintainers/ppa到系统的软件源中,使用此不受信任的PPA中的不受支持的软件包更新系统。

 deb http://ppa.launchpad.net/timekpr-maintainers/ppa/ubuntu oneiric main deb-src http://ppa.launchpad.net/timekpr-maintainers/ppa/ubuntu oneiric main 

此套餐包括:

  • Oneiric问题看错误报告….
  • 整洁的
  • 特立独行
  • 清醒
  • 业报
  • 贾蒂
  • 强悍
  • 哈迪

  • 什么是PPA以及如何使用它们?

问题:

我在这里报告Bug ,所以交叉你的手指等待….

介绍

我们可以通过命令检查用户是否已登录:

 who -u 

这给了我们一个输出:

 $ who -u jacob :0 2016-03-17 20:48 ? 2557 (:0) newuser :1 2016-03-17 20:50 ? 4466 (:1) 

在输出中,我们得到目标用户的pid,如果时间超过限制,则需要暂停。

解决方案

假设您的用户没有sudo权限:

此解决方案是一个小的后台脚本。 它将每天的使用量限制为定义的分钟数,以便在脚本的头部设置。 一旦设置(这不是太困难),它运行起来非常简单,之后不需要额外的操作。

为了防止可能打开的文件丢失不必要的数据,在目标用户的时间限制到期 60秒,他或她的DISPLAY上会显示一条消息:

在此处输入图像描述

剧本

 #!/usr/bin/python3 import subprocess import os import sys import time #--- set the time limit below (minutes) minutes = 120 #--- set the user name to limit below user = "newuser" uselog = "/opt/limit/uselog" datefile = "/opt/limit/currdate" def read(f): try: return int(open(f).read().strip()) except FileNotFoundError: pass def message(disp, user): return "DISPLAY="+disp+" su - "+user+" -c "+'"'+\ "notify-send 'User "+user+\ " will be logged off in 60 seconds'"+'"' currday1 = read(datefile) while True: time.sleep(10) currday2 = int(time.strftime("%d")) # check if the day has changed, to reset the used quantum if currday1 != currday2: open(datefile, "wt").write(str(currday2)) try: os.remove(uselog) except FileNotFoundError: pass # if the pid of the targeted process exists, add a "tick" to the used quantum check = subprocess.check_output(["who", "-u"]).decode("utf-8") pid = [l.split() for l in check.splitlines() if user in l] if pid: n = read(uselog) n = n + 1 if n != None else 0 open(uselog, "wt").write(str(n)) # when time exceeds the permitted amount, kill the process if n > minutes*6: disp = [d for d in [d[1] for d in pid] if all([":" in d, not "." in d])][0] subprocess.Popen(["/bin/bash", "-c", message(disp, user)]) time.sleep(60) pids = [p[-2] for p in pid] for p in pids: subprocess.Popen(["kill", p]) currday1 = currday2 

How to use

  1. On your desktop (or anywhere else), create a folder named: limit
  2. Copy the script into an empty file, save it as limit_use (no extension) inside the folder and make it executable
  3. Edit in the head of the script the user name to limit, and the maximum number of allowed minutes. 在示例中:

     #--- set the time limit below (minutes) minutes = 1 #--- set the user name to limit below user = "jacob" 
  4. Copy the folder to the directory /opt :

     cp -r /path/to/limit /opt 
  5. Now edit /etc/rc.local to make the script run it as root on startup:

     sudo -i gedit /etc/rc.local 

    Just before the line

     exit 0 

    another line:

     /opt/limit/limit_use & 

Explanation; how it works

  • Once per 10 seconds, the script looks if the targeted user is logged in. If so, it “adds” one “point” to a total usage, to be recorded in a file ( /opt/limit/uselog ). If the daily limit is reached, the script no longer allows the user to be logged in, kills its process if it exists.
  • On the day change (the date is recorded in a file, so reboot won’t help), the log file is deleted, allowing a new amount of usage time to build up.
  • Since the script runs on boot up , from rc.local only user(s) with sudo privileges can stop the script, even then only if the user knows the process name.

Stop the script

In case you’d like to stop the script, use the command:

 sudo kill "$(pgrep limit_use)" 

But you’d need the sudo password to do so.

I tried timekpr but did not got it working. Then made a variant of it which works on my Ubuntu. This is what one needs to do for this variant:

  1. Add time limit in /var/lib/timelimit/user_to_be_limited.limit file with root rights only. eg 1800 for 1800 seconds (30 minutes) daily limit.

  2. Create /usr/local/bin/timelimit.sh with root rights with following:

     #!/bin/bash pollTime=30 export DISPLAY=:0 while(true); do sleep $pollTime usersLogedIn=$( users|sed -e 's/\s\+/\n/g'|sort|uniq ) for userName in $usersLogedIn; do if [[ -e "/var/lib/timelimit/$userName.limit" ]] then if [[ ! -e "/var/lib/timelimit/$userName.time" || `( stat -c '%z' /var/lib/timelimit/$userName.time|cut -c9,10 )` != `date +%d` ]] then echo $pollTime > /var/lib/timelimit/$userName.time else timeUsed=$(( `cat /var/lib/timelimit/$userName.time` + $pollTime )) echo $timeUsed > /var/lib/timelimit/$userName.time fi if [[ `cat /var/lib/timelimit/$userName.time` -gt `cat /var/lib/timelimit/$userName.limit` ]] then export XAUTHORITY=/home/$userName/.Xauthority notify-send --icon=gtk-dialog-warning --urgency=critical -t 30000 "$userName" "You have 60 seconds left!" sleep 60 pkill -u $userName fi fi done done 
  3. Add to /etc/rc.local :

     sudo /usr/local/bin/timelimit.sh & 
  4. Restart Ubuntu

I just made an answer available easily. Code is explained on thread http://forums.linuxmint.com/viewtopic.php?f=213&t=77687 . In short: a limit configured in minutes per day, a cron job every minute, a message to user to keep him informed and a forced logoff.

To download and install this, open a Terminal and run the commands below:

 cd /tmp/ git clone https://github.com/Thomas-Baeckeroot/ParentalControl.git cd ParentalControl/ ./install.sh 

Administrator password will be requested during the installation process (to install the cron job, to copy the script, …). From there you will be guided for all. There is also an ./uninstall.sh at the same place just in case. It is build to work with all Ubuntu based distro (Mint, etc… probably all debian also). If any issue occurs please let me know, including system version and graphical environment in comments:

 uname -a echo $XDG_CURRENT_DESKTOP 

Thomas Baeckeroot