What's new

Custom cron job

  • 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!

privacyguy123

Senior Member
If I'm right I see erros in the logs about the ? in this cron statement because it is "non standard"

What is the correct way to run something every 45 seconds?

crond[1618]: user admin: parse error at ?

0/45 0 0 ? * * *
 
Perhaps this may help:


1696251601566.png
 
If I'm right I see erros in the logs about the ? in this cron statement because it is "non standard"

What is the correct way to run something every 45 seconds?
The lowest you can go is once every minute.
*/1 * * * *
 
If I'm right I see erros in the logs about the ? in this cron statement because it is "non standard"

What is the correct way to run something every 45 seconds?
NAT-PMP keep port open script.
For such cases where you want to run some task/cmds with a frequency < 60 sec., you can write a shell script in which you set up a while loop that encloses the desired tasks/cmds followed by the interval delay. I have done this before when reading from a FIFO pipe that was set up by another process, and because the FIFO buffer is rather small I had to read it every 2 seconds or so.

Here's a rough draft of what the script would look like:
Bash:
#!/bin/sh
####################################################################
# RunTaskEveryXseconds.sh
# Run some task/cmds every X seconds until told to exit.
####################################################################
set -u

# Set interval between runs #
intervalSecs=30

ScriptFName="${0##*/}"
LockDirPath="/tmp/var/${ScriptFName%.*}_d.LOCK"
ExitSemFile="/tmp/var/${ScriptFName%.*}_f.EXIT"

_ReleaseLock_()
{ rm -f "$ExitSemFile" ; rm -fr "$LockDirPath" ; }

_AcquireLock_()
{
   if mkdir "$LockDirPath" &>/dev/null
   then return 0 ; else exit 1 ; fi
}

trap "_ReleaseLock_; exit 0" HUP INT QUIT ABRT TERM
_AcquireLock_

echo "Entering while loop..."
while true
do
   echo "[$(date)]: Run some task/process every [$intervalSecs] sec."
   ...
   ## Run desired task/cmds here ##
   ...
   if [ -f "$ExitSemFile" ]
   then echo "Exiting while loop." ; break ; fi

   sleep "$intervalSecs"
done

_ReleaseLock_
exit 0

#EOF#

Then you can run the script in the background from one of the hook scripts (e.g. services-start) depending on the requirements or needs of the process or set of commands you're trying to run.
Bash:
/jffs/scripts/RunTaskEveryXseconds.sh &

My 2 cents.
 

Latest threads

Sign Up For SNBForums Daily Digest

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