Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 881
Jan Chris Bilek Avatar asked Jun 16 '26 08:06

Jan Chris Bilek


2 Answers

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
like image 153
SaiKiran Avatar answered Jun 17 '26 20:06

SaiKiran


Another option is a self-replicating 'at' job. Only advantage over cron is that it is less obvious, and also if you needed it to kick off not every X minutes, but X minutes after the last job completed. So your script will just contain a line to create a new 'at' job before it exits. Something like:

echo "/full/path/to/my/script > /root/myScript.at.log" | at now + X minutes
like image 24
caleb harfoot Avatar answered Jun 17 '26 22:06

caleb harfoot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!