shell脚本编写护眼程序

sh/bash/dash/ksh/zsh等Shell脚本
yalishizhude
帖子: 12
注册时间: 2010-10-01 21:46

shell脚本编写护眼程序

#1

帖子 yalishizhude » 2010-10-06 23:40

最近换了Ubuntu之后容易感觉头晕眼胀,因为之前在Windows下都有安装护眼软件,每隔一段时间会自动锁屏提示用户休息眼睛。google了好久都没有找到一个在Linux环境下好用的护眼软件,所以就自己用脚本写了一个简陋的版本,现在跟大家分享一下,希望各位程序员都能够注意自己的身体。程序不足之处还望大家指点。


运行环境:Ubuntu10.04下测试可行,需安装xlockmore

功能说明:该程序能每隔n分钟(n可让用户自行设定)自动锁屏,提醒用户休息眼睛;在锁屏前提前m分钟弹出窗口提示用户m分钟后将锁屏(m由用户设定),休息完毕后用户输入密码即可解除锁屏状态。

代码:
#!/bin/sh
#The program can lock screen automatically to protect your eyes.
#Author
# yalishizhude [email protected]
#History
# 2011-10-5 ver:1
#Copyright preserved ^-^
clear
echo "Welcome to use CloseYourEyes(beta)"
echo "--The program can remind you rest eyes every n minutes(n set by you) on rest\n"
read -p "How often do you want to have a rest?(default:50min)" interval
#set default interval time
test -z $interval && interval=50
echo "interval time: "$interval
#set default rest time
read -p "How many minute(s) do you want to be informed in advance?(default:1min)" advance
test -z $advance && advance=1
echo "advance time: "$advance
inform=$(($interval - $advance));
read -p "Are you sure the settings?(y/n)(default:y)" setting
test -z $setting && setting="y"

代码说明:clear清屏后显示欢迎信息,然后提示用户设定休息间隔时间(n分钟)和休息提前提醒时间(m分钟),test检测输入为空时设置默认值。在用户确定设置后即用while语句启动倒计时循环,此后sleep休眠 n-m分钟,用xterm命令弹出提示窗口,n分钟后xlock锁屏。

特别注意:

1.一定要装xlockmore软件,不知道怎么装的话google一下,或者xlock一下就会出现提示

2.一定要注意 []两边的空格,开始弄了好久都显示not command就是因为没注意这个问题,所以说做事情还是要注意细节。
上次由 yalishizhude 在 2010-10-07 22:10,总共编辑 1 次。
yalishizhude
帖子: 12
注册时间: 2010-10-01 21:46

Re: shell脚本编写护眼程序

#2

帖子 yalishizhude » 2010-10-06 23:40

:em11 :em11 :em11
头像
erlongshan
帖子: 161
注册时间: 2009-09-24 23:35

Re: shell脚本编写护眼程序

#3

帖子 erlongshan » 2010-10-07 1:13

朱德同志,辛苦了
欢迎加入ubuntu客栈,QQ群号:72697747
头像
momova
帖子: 3381
注册时间: 2007-07-11 21:43
系统: archlinux
来自: 东江边

Re: shell脚本编写护眼程序

#4

帖子 momova » 2010-10-07 1:20

这个不错,能不能设置锁屏的时候播放点音乐什么的呢?
我来了,我看见了,我征服了!
求勾搭,不管饭。
tusooa
帖子: 6548
注册时间: 2008-10-31 22:12
系统: 践兔
联系:

Re: shell脚本编写护眼程序

#5

帖子 tusooa » 2010-10-07 8:38

代码: 全选

#!/bin 
。。。
看你怎么执行?

代码: 全选

] ls -ld //
yalishizhude
帖子: 12
注册时间: 2010-10-01 21:46

Re: shell脚本编写护眼程序

#6

帖子 yalishizhude » 2010-10-07 9:45

将以上代码保存为RestEyes.sh
cd到目录下
sh RestEyes.sh
即可执行
yalishizhude
帖子: 12
注册时间: 2010-10-01 21:46

Re: shell脚本编写护眼程序

#7

帖子 yalishizhude » 2010-10-07 9:50

erlongshan 写了:朱德同志,辛苦了
为人民服务 :em06
头像
xiooli
帖子: 6956
注册时间: 2007-11-19 21:51
来自: 成都
联系:

Re: shell脚本编写护眼程序

#8

帖子 xiooli » 2010-10-07 10:13

开头那行没这么写的,一般是 #!/bin/bash 或 #!/bin/sh
yalishizhude
帖子: 12
注册时间: 2010-10-01 21:46

Re: shell脚本编写护眼程序

#9

帖子 yalishizhude » 2010-10-07 21:42

xiooli 写了:开头那行没这么写的,一般是 #!/bin/bash 或 #!/bin/sh
:em06 学习了
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: shell脚本编写护眼程序

#10

帖子 eexpress » 2010-10-07 21:51

桌面搞暗点嘛。
尤其浏览器什么的。
● 鸣学
头像
astolia
论坛版主
帖子: 6703
注册时间: 2008-09-18 13:11

Re: shell脚本编写护眼程序

#11

帖子 astolia » 2010-10-08 1:01

workrave不错,楼主想要的功能都有。源里就有
yalishizhude
帖子: 12
注册时间: 2010-10-01 21:46

Re: shell脚本编写护眼程序

#12

帖子 yalishizhude » 2010-10-13 17:34

astolia 写了:workrave不错,楼主想要的功能都有。源里就有
谢谢,很好很强大
zoeynehc
帖子: 7
注册时间: 2010-10-16 21:54

Re: shell脚本编写护眼程序

#13

帖子 zoeynehc » 2010-10-16 22:09

谢谢分享!! :em02
闭目身半躺,腰中酒凉
superharry
帖子: 5
注册时间: 2009-10-05 20:56

Re: shell脚本编写护眼程序

#14

帖子 superharry » 2010-11-04 20:01

这个脚本没写完吧 :em06
头像
cpustu
帖子: 31
注册时间: 2008-02-04 22:34
系统: Ubuntu 11.10
来自: 江苏南京

Re: shell脚本编写护眼程序

#15

帖子 cpustu » 2011-10-26 10:52

ubuntu11.10的软件中心里没这个软件怎么办?
回复