QuestionEverything
QuestionEverything

Reputation: 5097

Bash script for running two commands at specific intervals

I was playing around with xbacklight program in linux terminal.

What I am trying to do is, set my display to 0% brightness for 20 seconds at every 20 minutes.

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.

Upvotes: 2

Views: 256

Answers (2)

Idriss Neumann
Idriss Neumann

Reputation: 3838

For permanent use, cron is the best solution. For temporary use, there are alternatives.

For example, you could also use watch to do this job :

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

Using bash only :

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

Upvotes: 2

John Zwinck
John Zwinck

Reputation: 249123

Do it using 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.

Upvotes: 4

Related Questions