[英]Bash script for running two commands at specific intervals
I was playing around with xbacklight program in linux terminal. 我在Linux终端中玩xbacklight程序。
What I am trying to do is, set my display to 0% brightness for 20 seconds at every 20 minutes. 我想做的是每20分钟将显示屏的亮度设置为0%,持续20秒。
Briefly, something like: 简而言之,类似:
in every 20 mins:
xbacklight -set 0%
continue this way for 20 seconds
then:
xbacklight -set 100%
How can I set these timeouts properly? 如何正确设置这些超时时间?
Thanks in advance. 提前致谢。
Do it using cron: 使用cron执行此操作:
*/20 * * * * xbacklight -set 0\% && sleep 20 && xbacklight -set 100\%
Note the need to escape the percent signs--they mean something special to cron otherwise. 请注意,必须避开百分号-这对cron而言意味着特殊。
For permanent use, cron
is the best solution. 对于永久使用, cron
是最佳解决方案。 For temporary use, there are alternatives. 对于临时使用,还有其他选择。
For example, you could also use watch
to do this job : 例如,您还可以使用watch
来完成这项工作:
watch -n1200 "xbacklight -set 0% && sleep 20 && xbacklight -set 100%"
Using bash only : 仅使用bash:
while [ 1 ]; do xbacklight -set 0% && sleep 20 && xbacklight -set 100%; sleep 1200; done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.