Score:0

Crontab runs itself early

ru flag

I have a set a crontab to run a bash script every 10 minutes. But it runs the shell script so early. It runs it like after 7 minutes adding it. Why does it do that? How can I fix it? I gave my cron below:

*/10 * * * * cd /home/myuser/mydir && bash mybashscript.sh
Score:4
vn flag

That's not how cron works. Cron does not care when you made changes to the crontab (this wouldn't make much sense anyway), it only looks at which specific times during the day you want things to happen.

The expression */10 in the first cell means: "Every 10th minute (starting from 0)". This is equivalent of writing 0/10. This means no matter when you enter this expression, it will run on every 10th minute at 10, 20, 30, 40, 50 and 00.

If you want every 10th minute at odd numbers, give a different starting value (eg. 5), like this: 5/10. This will run at 05, 15, 25, 35, 45 and 55.

Crontab.guru is a good place to test your cron expressions.

Erikli avatar
ru flag
I gave a odd number but it still doesn't really require my request. How can I do my request?
Artur Meinild avatar
vn flag
You can't - that's not how cron works. There's nothing more to it.
Score:3
cn flag

That is not how cron works. cron will run */10 every 10th minute of an hour.

If you want to have it run after a specific time has passed use the interactive at

echo "1" | at now + 7 minutes

at understands complex wording like "2:00 PM tomorrow" and "now + 20 days"

Mind that you can use at in cron if you really want to have it run in 7 minutes (for instance @reboot {script} at now + 7 minutes would start the script 7 minutes after a reboot) but it is intended to be used interactive or from scripts.

A couple of methods using time at understands:

[CC]YYMMDDhhmm[.ss] now midnight noon teatime AM PM

now + N minutes/hours/days/weeks/months/years

I sit in a Tesla and translated this thread with Ai:

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.