Tak*_*kat 66 bash parental-controls software-recommendation
需要限制我的孩子(7、8 岁)的帐户访问我们的计算机(不仅是互联网),直到他们长大到可以自己管理为止。在此之前,我们需要能够定义以下内容:
在 11.10 中,用于完成这项工作的以下所有内容不再起作用:
还有其他选择吗?
hhl*_*hlp 42
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.
Run Code Online (Sandbox Code Playgroud)
以下是一组典型规则的示例:
login ; * ; !bobby ; MoTuWeThFr0800-2000
login ; * ; !root ; !Al0000-2400
http ; * ; !bobby ; MoTuWeThFr0800-2000
http ; * ; !root; !Al0000-2400
Run Code Online (Sandbox Code Playgroud)
这些规则限制用户 bobby 在 0800 和 2000 之间登录,并且还限制在这些时间访问 Internet。Root 可以随时登录,也可以随时浏览 Internet。
注意:系统将这些规则的错误记录为 syslog(3)。
使用 Ubuntu Linux,可以为您的计算机分配时间限制,以防止一个或多个用户连接到您的系统。例如,通过时间限制,您可以限制孩子对计算机的访问(简而言之,一种家长控制),甚至可以在特定时间内保护与您的服务器的连接。
手动配置
明白你会做什么
在本教程中,我们将使用 PAM(Pluggable Authentication Modules,英文Pluggable Authentication Modules)。它允许您在用户连接时控制用户身份验证。然后,我们将使用安全配置文件来定义允许的登录时间。这些操作可以在任何版本的 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
Run Code Online (Sandbox Code Playgroud)
如果我们想阻止与计算机的连接,我们将不得不更改 gdm 服务。编辑文件 so gdm 并添加以下代码行(在文件末尾):
account required pam_time.so
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
编辑文件time.conf。一些解释和例子(英文)介绍。要设置访问计划,请复制并粘贴以下代码行(一如既往地在文件末尾):
*;*;user;scheduler
Run Code Online (Sandbox Code Playgroud)
输入要阻止的登录帐户,而不是用户字段。
如果要阻止多个用户,请连续输入他们的登录名,以 | 分隔。操作员。例如,如果我想冻结 Patrick、John 和 Emily 的账户:
*;*;Patrick|jean|emilie;scheduler
Run Code Online (Sandbox Code Playgroud)
缺点是,如果你想阻止所有用户访问系统,特别是一个用户,请使用!在有关人员面前。例如,如果我要拒绝所有用户访问计算机,除了 Nicolas 和 Xavier:
Nicolas *;*;!|xavier;scheduler
Run Code Online (Sandbox Code Playgroud)
现在转向现场区域。在该字段中,可以选择允许连接的天数和小时数。您必须首先使用以下缩写指定星期几:
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
Run Code Online (Sandbox Code Playgroud)
小心不要混淆缩写 Wk 和 Wd 会产生误导!在互联网上识别特别差:您可以轻松找到相互矛盾的信息!
然后,我们指定截止日期。这些应该被格式化为 24H,由 4 位数字组成。例如,要将 3:17 pm 限制到 6:34 pm,我们写:1517-1834。为了仅允许 Marie 在星期二下午 3:17 到下午 6:34 进行连接,我们获得了结果:
*;*;marie;Tu1517-1834
Run Code Online (Sandbox Code Playgroud)
这些时间以外的连接将被禁止。对于用户,可以使用运算符 | 和!表示多次(the! then 表示允许所有登录时间,但要显示的时间除外)。
代码行开头的两颗星(通配符)分别是和 tty 服务字段。既然要阻止对系统的所有访问,就没有必要指定要阻止什么服务或什么 tty。但是,如果您想阻止使用特定服务,只需将其指定为以下示例:
login;tty1|tty4|tty5;marie;!Wd0000-2400
Run Code Online (Sandbox Code Playgroud)
因此,用户结婚无法在周末连接到 TTY、4 和 5。
限制时间表的一些例子
每天下午 1:20 至下午 3:20 以及下午 4:00 至晚上 8:30 允许 mathilde 连接:
*;*;mathilde;Al1320-1520|Al1600-2030
Run Code Online (Sandbox Code Playgroud)
Stone、Frank 和 Florian 被允许连接到工作日的下午 2:00 到下午 6:45,以及周末的下午 2:00 到晚上 10:15:
*;*;Stone|franck|florian;Wk1400-1845|Wd1400-2215
Run Code Online (Sandbox Code Playgroud)
永远不允许 Olive 连接。jessica 可以在星期三下午 1:00 到下午 4:00 登录:
*;*;olivier;!Al0000-2400
*;*;jessica;We1300-1600
Run Code Online (Sandbox Code Playgroud)
2 条不同的线路,针对每个用户的两个不同时间 会话到期
当会话过期(超过用户已连接的时间)时,PAM 可以到达用户。虽然 mathilde 在允许的时间内连接,但超过这些时间是完全免费的!为此,我们将使用一个新程序:“cron”。此应用程序每隔一段时间执行命令。在我们的例子中,我们将使用命令“skill-KILL-u”在会话到期时断开用户连接。处理非常简单。只需编辑文件“/etc/crontab”。然后添加以下代码行:
Minute Hour Day * * (s) root skill -KILL -u User
Run Code Online (Sandbox Code Playgroud)
和以前一样,替换所需的分钟字段计划和时间。然后按禁止日期 (s) 填写日期 (s),或简单地键入星号 (*) 以表示一周中的所有天数。最后,更改要阻止的登录帐户使用的字段,瞧!
天不通知的方式跟cron工作一样!以下是此程序要使用的缩写列表:
mon : monday fri : friday
tue : tuesday sat : saturday
wed : wednesady sun : sunday
thu : thursday * : all hours
Run Code Online (Sandbox Code Playgroud)
工作的一些例子cron(上一节中有时间的例子)
jessica 可以在星期三下午 1:00 到下午 4:00 登录
-> 断开连接:星期二下午 4:00。
00 16 * root * wed skill -KILL -u jessica
Run Code Online (Sandbox Code Playgroud)
每天下午 1:20 至下午 3:20 以及下午 4:00 至晚上 8:30 允许 mathilde 连接。
-> 断开连接:每天,东部时间晚上 8:30 至下午 3:20。
20 15 * * * root skill -KILL -u mathilde
30 20 * * * root skill -KILL -u mathilde
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
命令 Skill-KILL-u 将用户与 GUI 以及 TTY 断开连接。它非常适合服务器管理员。但是,此命令是即时的,并且会在没有通知的情况下断开连接。因此,最好防止相关计算机或网络的用户安装此设备!
可以wall通过cron在时间范围结束前几分钟启动的命令阻止用户,该命令将显示在所有用户的终端中。
40 18 * * Mon,Tue,wed,thu,fri root echo "end of session in 5 minutes" | wall
Run Code Online (Sandbox Code Playgroud)
为了防止用户使用 GUI 可以使用notify-send包libnotify-bin中的 wall 命令来代替
40 18 * * Mon,Tue,wed,thu,fri stone DISPLAY=:0 notify-send "end of session in 5 minutes"
Run Code Online (Sandbox Code Playgroud)
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 日志文件:
或在调试模式下运行 LightGdm:
LightDM --debug
或报告错误:
ubuntu-bug lightdm
小智 9
如果您正在处理某事,自动注销非常令人沮丧。它很暴力,很残忍,很粗鲁。你的年龄并不重要。当您只是对计算机上瘾时这是一回事,而当您跟踪时间并在设法单击提交按钮或保存文档之前被踢出 5 秒时,情况就大不相同了。我建议您考虑使用自动提醒而不是自动踢球。这将教会您的孩子相互尊重,并允许彼此心甘情愿地使用计算机。
甚至还有更轻的替代品。首先跟踪每个孩子使用计算机的时间,并将收集到的数据提供给所有人,以便他们可以看到。当我在一个满是成年人的办公室中担任网络管理员时,仅此一项非常简单的事情(适用于所花费的互联网带宽)就挽救了我的生命。关于每台计算机的带宽使用情况的公共统计数据(只是字节数,而不是访问站点列表等信息的去匿名化信息)将情况从“我 - 反对他们的邪恶贪婪管理员 - 可怜的被滥用的办公室用户”转变为“男人,你下载量比我多5倍,太糟糕了!” “对不起,我确实下载了,我在午休时间看了很多 youtube,以这种速度不会再这样做了” - 我只是被排除在对抗场景之外。
可以在 11.10 运行 LightDM 中使用,通过添加以下行来为用户设置限制 /etc/pam.d/lightdm
account required pam_time.so
Run Code Online (Sandbox Code Playgroud)
我们可能需要删除libpam-smbpass以启用用户切换,直到错误 #835310被修复。
应用程序窗口中定义的所有限制都按照 timekpr GUI 中的定义工作。
要在 Unity 中显示 timekpr-client 图标,我们需要在 Unity 面板设置中加入白名单 'timekpr',此外我们需要添加Unity到以下行中/etc/xdg/autostart/timekpr-client.desktop:
OnlyShowIn=GNOME;XFCE;KDE;Unity;
Run Code Online (Sandbox Code Playgroud)
要开始倒计时,我们可能需要启动 timekpr 守护进程
/etc/init.d/timekpr start
Run Code Online (Sandbox Code Playgroud)
timekpr的较新版本/叉被发布的Ubuntu 14.04 Eduards Bezverhijs他ppa:mjasnik/ppa。
小智 6
我也有这个问题。所以我编写了kidtimer 脚本,它可以让您定义使用时间和总数。该项目可以在 Github 上的以下位置找到:
这是安装和使用它的方法:
将代码复制并粘贴到名为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 n n
01 n n
02 n n
03 n n
04 n n
05 n n
06 n n
07 n n
08 y y
09 y y
10 y y
11 y y
12 y y
13 y y
14 y y
15 y y
16 y y
17 y y
18 y y
19 y y
20 n n
21 n n
22 n n
23 n n
#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 <user> <minutes|reset>"
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 <user> <minutes> ... Increases allowed time for the day."
echo "logout <user> ... 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
Run Code Online (Sandbox Code Playgroud)执行它:
sudo ./kidtimer.install
Run Code Online (Sandbox Code Playgroud)运行:
sudo kidtimer
Run Code Online (Sandbox Code Playgroud)设置现有用户帐户。
完毕。
sudo kidtimer help
Run Code Online (Sandbox Code Playgroud)
sudo kidtimer addtime user minutes
Run Code Online (Sandbox Code Playgroud)
/etc/kidtimer/kid.list
/etc/cron.d/kidtimer
/usr/local/kidtimer/schedule/<user>
/usr/local/kidtimer/time/<user>.ttl
/usr/local/bin/kidtimer
Run Code Online (Sandbox Code Playgroud)
该应用程序用于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.
Run Code Online (Sandbox Code Playgroud)
您可以通过添加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
Run Code Online (Sandbox Code Playgroud)
该软件包可用于:
哈代
问题 :
尽管有第三方应用程序可以执行此操作,但您可以创建自己的应用程序。步骤总结:
gedit创建脚本lock-screen-timerlock-screen-timerlock-screen-timer为可执行文件gedit创建脚本lock-screen-timer打开Terminalusing Ctrl++Alt并T输入:
gedit lock-screen-timer
Run Code Online (Sandbox Code Playgroud)
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 Nov 13, 2021.
# UPDT: Updated to support WSL (Windows Subsystem for Linux)
# Remove hotplugtv. Replace ogg with paplay.
# May 30 2018 - Cohesion with multi-timer. New sysmonitor indicator style.
# Nov 13 2021 - Wrap long lines with \ continuation. Shorten comments.
# 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 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 "Lock screen in: $MINUTES Minutes" > ~/.lock-screen-timer-remaining
sleep 60
done
rm ~/.lock-screen-timer-remaining # Remove countdown work file
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.
Run Code Online (Sandbox Code Playgroud)
然后切换回空窗口并使用+gedit粘贴代码。保存文件并退出编辑器回到命令提示符。CtrlV
lock-screen-timer为可执行文件现在我们需要通过键入以下内容使脚本可执行:
chmod +x lock-screen-timer
Run Code Online (Sandbox Code Playgroud)
在从 GUI 调用脚本之前,我们将从终端调用它,以便查看是否显示任何错误消息:
~/lock-screen-timer
Run Code Online (Sandbox Code Playgroud)
系统会提示您输入分钟数:
设置所需的分钟数,然后单击“确定”启动计时器。当还剩 15、10、5、3、2 和 1 分钟时,会听到系统声音,并出现消息气泡,建议何时锁定屏幕。屏幕锁定后,您需要输入密码才能解锁屏幕。
Nautilus 定义了当我们双击可执行脚本(当它是文件显示窗口或桌面上的链接时)会发生什么。正常行为是使用 编辑脚本gedit。我们想要更改此行为以使其被执行。
启动 Nautilus 并导航到包含lock-screen-timer. 左键单击它一次以使其获得焦点。将鼠标悬停在顶部菜单栏上,直到出现“文件编辑...”菜单,使用:
Edit下拉菜单Properties选项Behavior选项卡Executable Text FilesRun executable text files when they are opened上一节lock-screen-timer仍然有重点。如果没有,请导航到该脚本并左键单击它一次以使其获得焦点。然后使用:
Make Link。Link to lock-screen-timer。现在您可以双击桌面快捷方式链接并运行脚本。出现一个对话框以获取分钟数。出现两个按钮Cancel和OK。如果单击X关闭窗口,则与选择 相同Cancel。
计时器运行后,您再次双击它,第一个运行的副本将被“杀死”。您现在可以开始新的屏幕锁定倒计时或单击Cancel不倒计时。
当锁屏计时器运行时,它会记录文件还剩多少分钟~/.lock-screen-timer-remaining。您可以使用命令查看此文件watch或将其显示在 Ubuntu 的系统托盘/应用程序指示栏上,如本答案顶部所示。要在通知区域中显示剩余时间,请按照此问答中的说明进行操作:BASH 可以在系统托盘中显示为应用程序指示器吗?。
| 归档时间: |
|
| 查看次数: |
57943 次 |
| 最近记录: |