What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Minimum crontab resolution 2 minutes?

Mikii

Regular Contributor
Hi. I am trying to run a crontab every minute, but is looks like the minimum time resolution I can get is actually TWO minutes.

this happens on a RT-AX88U Pro with Firmware: 3006.102.5.


Code:
crontab -l
*/1 * * * * sh /tmp/mnt/MicScripts/micscripts/time.sh #timing#

the script code is very basic:

Code:
PATH=/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin
export PATH

echo "SCRIPT start: $(date '+%F %T')" >> /tmp/mnt/MicScripts/micscripts/loop_timing.log

for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18; do

sleep 3

done

echo "SCRIPT end: $(date '+%F %T')" >> /tmp/mnt/MicScripts/micscripts/loop_timing.log

echo "----------------------------------------" >> /tmp/mnt/MicScripts/micscripts/loop_timing.log

but the log shows the script runs every TWO minutes

Code:
SCRIPT start: 2025-09-18 11:07:00
SCRIPT end: 2025-09-18 11:07:54
----------------------------------------
SCRIPT start: 2025-09-18 11:09:00
SCRIPT end: 2025-09-18 11:09:54
----------------------------------------
SCRIPT start: 2025-09-18 11:11:00
SCRIPT end: 2025-09-18 11:11:54
----------------------------------------
 
OK I've recreated the problem on my router.

By turning on verbose logging we can see that crond tries to determine whether a task has completed by looking for the pid every 10 seconds. It won't start the same task again if it thinks it's still running. However, if the task is still running at the 50 second point it assumes it's still running 10 seconds later when it's determining which new tasks should be started. So the only solution is to make sure your job completes before the 50 second point.
 
Reduce the script runtime to about 30 seconds and test again. My guess is that the script will run once a minute.

Thanks for the tip. Haven't tried yet (my objective is to run a command every three seconds, hence the loop)... But I found out that running the crontab command asynchronously seems to help. So I moved the schedule to two minutes and extended the loop to two minutes on my main script.

Code:
cru a CheckWebCommand "*/2 * * * * sh /tmp/mnt/MicScripts/micscripts/newcheckwebvpncommand.sh &"
 
I was about to post the same thing (having just tested it). Running the task in background gets around the 50 second problem as it spawns a separate process with a different pid. So this:

Code:
cru a timings "* * * * * sh /tmp/mnt/MicScripts/micscripts/time.sh &"

You just have to make sure your script doesn't overlap with itself.
 
Last edited:
Yes. It seems like the next cron timing is taken from the end time of the script, not the start...
so if a script ends at 3.52.33 seconds, next one will run at at 3.54.00. That is my impression.

Or maybe, as you say, this only happens if the script ends within the last 10 seconds window.
 
I think this shows the problem:
Rich (BB code):
Sep 18 12:17:00 crond[6549]: file admin:
Sep 18 12:17:00 crond[6549]:  line sh /tmp/home/root/test.sh
Sep 18 12:17:00 crond[6549]:  job: 0 sh /tmp/home/root/test.sh
Sep 18 12:17:00 crond[7165]: child running /bin/sh
Sep 18 12:17:00 crond[6549]: USER admin pid 7165 cmd sh /tmp/home/root/test.sh
Sep 18 12:17:10 crond[6549]: wakeup dt=10
Sep 18 12:17:20 crond[6549]: wakeup dt=10
Sep 18 12:17:30 crond[6549]: wakeup dt=10
Sep 18 12:17:40 crond[6549]: wakeup dt=10
Sep 18 12:17:50 crond[6549]: wakeup dt=10
Sep 18 12:18:00 crond[6549]: wakeup dt=10
Sep 18 12:18:00 crond[6549]: file admin:
Sep 18 12:18:00 crond[6549]:  line sh /tmp/home/root/test.sh
Sep 18 12:18:00 crond[6549]:  job: 7165 sh /tmp/home/root/test.sh
Sep 18 12:18:00 crond[6549]: user admin: process already running: sh /tmp/home/root/test.sh
Sep 18 12:19:00 crond[6549]: wakeup dt=60
Sep 18 12:19:00 crond[6549]: file admin:
Sep 18 12:19:00 crond[6549]:  line sh /tmp/home/root/test.sh
Sep 18 12:19:00 crond[6549]:  job: 0 sh /tmp/home/root/test.sh
Sep 18 12:19:00 crond[7571]: child running /bin/sh
Sep 18 12:19:00 crond[6549]: USER admin pid 7571 cmd sh /tmp/home/root/test.sh
Sep 18 12:19:10 crond[6549]: wakeup dt=10
Sep 18 12:19:20 crond[6549]: wakeup dt=10
Sep 18 12:19:30 crond[6549]: wakeup dt=10
Sep 18 12:19:40 crond[6549]: wakeup dt=10
Sep 18 12:19:50 crond[6549]: wakeup dt=10
Sep 18 12:20:00 crond[6549]: wakeup dt=10
Sep 18 12:20:00 crond[6549]: file admin:
Sep 18 12:20:00 crond[6549]:  line sh /tmp/home/root/test.sh
Sep 18 12:20:00 crond[6549]:  job: 7571 sh /tmp/home/root/test.sh
Sep 18 12:20:00 crond[6549]: user admin: process already running: sh /tmp/home/root/test.sh
 

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top