Score:1

Question about alternating commands every minute in Cron

us flag

I've been editing my crontab with crontab -e -u, and this is the contents:

*/1 * * * * export DISPLAY=:0 && xset dpms force off 

*/1 * * * * export DISPLAY=:0 && xset dpms force on

How do I make the on time holding for 1 minute, so the display is off for 1 minute then on 1 minute?

Wayne Vosberg avatar
bd flag
Possible duplicate: https://unix.stackexchange.com/questions/25684/how-to-access-x-display-from-a-cron-job-when-using-gdm3
Helex Chong avatar
us flag
still the same ...
bac0n avatar
cn flag
I really don't understand what you are trying to achieve.
Helex Chong avatar
us flag
i want to make my display off 1 minute then on 1 minute.... but now its able to off after 1 minute... but not able to on for another 1 minute ...its will on awhile like 1 sec then turn back to off
Score:5
vn flag

It sounds like you want crontab lines that execute a command at alternating minutes, like the first command at even minutes (0,2,4 etc.) and the second command at odd minutes (1,3,5 etc.).

This can be done in the following way:

0-59/2 * * * * export DISPLAY=:0 && xset dpms force off 

1-59/2 * * * * export DISPLAY=:0 && xset dpms force on

Explanation:

The minute entry here makes use of 2 different elements - ranges and step values.

The range has the format ?-?, so we define two different ranges, starting 1 minute apart (0-59 and 1-59).

The /2 part is the step value. By using this, we tell cron to only execute at every other value in the range.

By using the full possible minute range (but different starting values), we ensure that the commands run at every alternating minute, but 1 minute apart.

Fun fact:

The first range could also be entered as 0-58 and it wouldn't make a difference (since odd values are skipped in this range).

Helex Chong avatar
us flag
Wow!!thank you ....its work thank you thank you
Artur Meinild avatar
vn flag
You're welcome! :-) Please mark the answer as accepted with the green tick mark. Thanks.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.