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值
00 * * * * display=`/home/hoping/bin/initx` && export DISPLAY=$display && /usr/bin/gnome-screensaver-command --lock
原理很简单,每隔一个小时就锁屏一次
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
相关文章推荐
- Ubuntu 利用 crontab 和 notify-send 定时发送桌面通知,提示该休息啦
- 【树莓派自动化应用实例】整点提醒自己休息五分钟
- Cron 的在ubuntu 定时执行自己的程序&& Python获取当前 脚本文件的路径。
- VC 定时提醒自己休息
- 提醒自己装完UBUNTU后要做的(持续更新)
- Ubuntu下配置FLTK的一点经验及使用FLTK编写休息提醒软件
- 【树莓派自动化应用实例】整点提醒自己休息五分钟
- 【树莓派自动化应用实例】整点提醒自己休息五分钟
- 【原创】利用Ubuntu的cron服务来定时启动和关闭motion
- 为了提醒自己休息特意写的
- 【原创】利用Ubuntu的cron服务来定时启动和关闭motion
- 如何利用Bacon 2D来在Ubuntu平台上制作自己的游戏
- 一个VB小程序,提醒自己上下班打卡和每小时休息
- 利用Ubuntu 9.04 + 开源的 darwinstreamingserver 5.5.5建设自己的流媒体服务器
- 自己实现集合框架(五):利用单链表解决约瑟夫环问题
- 在做mes系统时,利用D7 IdMessage&IdSMTP发送邮件,从盒子上学习了不少的东西,自己整理了一下,想share给新手,学习参考!
- ubuntu添加自己的应用程序桌面图标
- 利用Xapian构建自己的搜索引擎:Document、Term和Value
- 「后台之路第1篇」Ubuntu上利用Eclipse搭建第一个Servlet工程
- CronHowto - Community Ubuntu Documentation