Jan Bílek Jan Bílek - 1 month ago 6
Linux Question

Crontab setting - execute script every 55 minutes

I found a interesting thing during creation of my

crontab
setting.

I used this command:

crontab -e


and fill this line:

*/55 * * * * export DISPLAY=:0 && /home/user/Documents/script.sh $2>/dev/null


My idea was create scheduler, which start
script.sh
every 55 minutes.

But this script is execute in this times (for example):

08:55, 09:00, 09:05, 09:55, 10:00, 10:05, ...


and I don't know why.

Can someone explain me that?

Answer

Replace the script like this and it should work.

 */5 * * * * [ $(( $(date +%s) / 60 % 55 )) -eq 0 ] && export DISPLAY=:0 && /home/user/Documents/script.sh $2>/dev/null

minute-hour-day-month-year

*   any value
,   value list separator
-   range of values
/   step values