您的位置:首页 > 其它

ubuntu下利用cron来提醒自己休息

2013-05-28 08:51 921 查看
原来使用windows的时候用爱眼卫士,提醒自己一个小时起来活动一下,现在换成了ubuntu,于是就想用cron直接提醒自己休息一下

原理很简单,每隔一个小时就锁屏一次

DISPLAY=:0

00 * * * * /usr/bin/gnome-screensaver-command --lock

注意上面的DISPLAY=:0,如果没这个变量,gnome-screensaver-command不会起效,而会报一条错误

Failed to get session bus: Error spawning command line `dbus-launch --autolaunch=903fc0c1b3535fe8f55930a05120822c --binary-syntax --close-stderr': Child process exited with code 1

如果restart了gnome-sessoin那么你的DISPLAY可能就不是:0了,因此写了一个脚本为自动获取当前的DISPLAY值

#!/bin/sh

if [ "$DISPLAY" != "" ]; then
echo $DISPLAY
exit
fi

if [ "$USER" = "" ]; then
USER=`whoami`
fi

pinky -fw|awk -v user=$USER 'NF == 6{if($1 == user){ print $6}}'|awk 'NR==1{print $0}'


00 * * * * display=`/home/hoping/bin/initx` && export DISPLAY=$display && /usr/bin/gnome-screensaver-command --lock
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: