Can a crontask only activate once?

Let's say I define a scheduled task in openwrt to activate once every 10 minutes, is there a way to define this task to activate only once, and not on repeat every 10 minutes?

I am using openwrt version 18.06

which one is it ?

sleep 600; execute task script ?

time to upgrade ?

2 Likes

Thing is, I read in the forum that sleep command should not be used with long periods of time, especially in startup, so where would be a safe place to run sleep 600?

and unfortunately, there is no better openwrt version for my hardware, believe me, I tried looking. I am using a 8devices komikan chip

I can imagine it can behave unreliably, if the device clock get synced during the sleep.

loop the date/time, when the year's 202? ( = in sync), start your sleep.

Excellent, then use cron as you originally noted.

But personally, I'd use the startup script. Are you sure you didn't confuse the two?

Can you link that post?

But cron will keep running the command every 10 minutes, not just once, right?

Write a script so it doesn't repeat.

e.g.

  • make a variable $already_ran_foo default 0, set to 1 after script runs
  • or make a similar file in /tmp
3 Likes

you can create a semaphor file

run 1st time and create file /tmp/somefile.name during execution
run every other time, check if /tmp/somefile.name exists, exit.

3 Likes

Thank you @frollic and @lleachii for your answers!

1 Like

Frollic already asked this, but what you actually want regarding the timing?
"every 10 minutes" and "activate only once, and not on repeat every 10 minutes" sound quite different.

Do you want something that

  • runs once after the boot has completed, a few minutes after the boot?
  • runs every 10 minutes?
  • is tried every 10 minutes until it succeeds once, then stop?
    (based on earlier discussion, possibly you want this)

Cron plus semaphore file, like suggested by frollic and lleachii, would be right for the last option.

Note that the benefit of creating the semaphore file in /tmp (=ramdisk), is that it will get automatically cleared at the next boot.

4 Likes

For that, I'd probably use the semaphore to tell me when it ran, like this.

#!/bin/sh

semaphore="/var/run/run_once.status"

if [ -e "$semaphore" ] ; then
        exit 0
fi

echo "Starting..."
ls
echo "Done."

date > "$semaphore"
4 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.