繁体   English   中英

Bash脚本,用于以特定间隔运行两个命令

[英]Bash script for running two commands at specific intervals

我在Linux终端中玩xbacklight程序。

我想做的是每20分钟将显示屏的亮度设置为0%,持续20秒。

简而言之,类似:

in every 20 mins:
     xbacklight -set 0%
     continue this way for 20 seconds

     then:
         xbacklight -set 100%

如何正确设置这些超时时间?

提前致谢。

使用cron执行此操作:

*/20 * * * * xbacklight -set 0\% && sleep 20 && xbacklight -set 100\%

请注意,必须避开百分号-这对cron而言意味着特殊。

对于永久使用, cron是最佳解决方案。 对于临时使用,还有其他选择。

例如,您还可以使用watch来完成这项工作:

watch -n1200 "xbacklight -set 0% && sleep 20 && xbacklight -set 100%"

仅使用bash:

while [ 1 ]; do xbacklight -set 0% && sleep 20 && xbacklight -set 100%; sleep 1200; done

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM