Run Cron Job every 45 minutes with Node-Cron

dynamic cron job nodejs
node-cron example github
cron job in node js express
node-cron not working
nodejs batch job
mongoose cron job
nestjs cron job
node-cron run every second

I'm using node-cron to run scheduled jobs. I want the jobs to run every 45 minutes, but its acting strangely

Here's the pattern I'm using

'00 */45 * * * *'

I started my script at Tue Jun 17 2014 08:17:39 GMT+0000 (GMT)

Here's are the first couple of times the job was executed

1. Tue Jun 17 2014 08:45:03 GMT+0000 (GMT)

2. Tue Jun 17 2014 09:00:01 GMT+0000 (GMT)

3. Tue Jun 17 2014 09:45:02 GMT+0000 (GMT)

This is definitely not what I expected or want. All I want is to run the Jobs every 45 minutes. Can anyone help me with the pattern? Thanks :)

Run Cron Job every 59 minutes (1 hour) with Node-Cron · Issue , I'm more familiar with cron than with node-cron. I just need to run an task each hour, every day. Is this right? var CronJob = require('cron'). In standard cron, there is no syntax to specify running a job every 45 minutes. A specification of 0/45 * * * * would run a job twice each hour, at 0 and 45 minutes after the hour.

I'm more familiar with cron than with node-cron, but I've taken a quick look at the documentation.

If I understand it correctly, node-cron uses a syntax similar to that used by cron, but with an additional "seconds" field. So where a cron job might have:

# min hour mday month wday command
*/15  *    *    *     *    some-command

to schedule some-command to run every 15 minutes, node-cron would use a similar syntax to specify the time to run:

'0 */15 * * * *'

(with an additional field to specify seconds), but it executes a specified JavaScript function, not an external command.

In standard cron, there is no syntax to specify running a job every 45 minutes. A specification of 0/45 * * * * would run a job twice each hour, at 0 and 45 minutes after the hour. To run a job every 45 minutes (at 00:00, 00:45, 01:30, 02:15, ..., i.e., 32 times per day) you'd have to schedule it to run every 15 minutes, and then invoke a script that checks the current time to decide whether to do anything.

Or you can write an exhaustive list of all the times you want the job to run:

 0  0 * * * some-command
45  0 * * * some_command
30  1 * * * some_command
15  2 * * * some_command
# 28 lines omitted

I'd definitely want to write a script to generate this list.

(This is workable because 24 hours happens to be a multiple of 45 minutes. You couldn't run something every 35 minutes this way.)

A similar approach should work for node-cron. Schedule the function to run every 15 minutes, and invoke a function that checks the current time to decide whether to run. For example, you can check whether the number of minutes since midnight modulo 45 is zero. (You might want to allow for a small variance in case the scheduling is not exact.)

I don't know JavaScript well enough to suggest the best way to write this function, but it should be reasonably straightforward.

Or write 28 lines to specify all the times you want it to run.

Cron job for every 2 minutes. · Issue #223 · kelektiv/node-cron · GitHub, How can I run a Cron job for every 2 minutes. '* 59 * * * * *' will run every second, only on the 59th minute of the hour. Usually you want to set all *'s that are to the left of the largest unit you're specifying. Like @liukun shows. Run cron on second 0 of the 59th minute. Everything else is * so it'll do this for every hour, day, month, etc.

There is no direct way to do this. However, we can get the result by intercepting the schedule using a shell command within the target script.

First, run the script at every 15 minutes:

*/15 * * * * <target_script>

Then, within the target_script, place the following code before actual codes:

#!/bin/sh

# Exit except at 0:45, 1:30, 2:15, 3:00, 3:45 etc

if ! echo "((`date +%-H`*60)+`date +%-M`)/45" | bc -l | grep "\.0*$" &> /dev/null;
then exit 1;
fi

# Your actual code goes here;

Run Periodic Tasks in Node with node-cron, 1: Minute (0-59); 2: Hour (0-23); 3: Day (0-31); 4: Month (0-12, where 12 is December) Cron would then run this script at 5:45pm on the 3rd day of every month. Run a Cron Job Every Minute If you want to run a program or script in the background on Linux then cron job is very important. With the help of cron jobs, you can execute a program or script in the background after a given interval of time. Let’s take a look at some of the real life examples of cron jobs.

You need to write a script as a wrapper to decide if the actual command shall be executed at every 45 minutes. That's 0, 45, 30 (= 45 + 45 - 60), 15 (= 30 + 45 - 60), 0 (= 15 + 45 - 60). so, the minutes to run the script shall be 0,15,30,45.

The command date +%M may be helpful in the shell script.

Node cron, run every midnight - node.js - html, CronJob; var job = new CronJob('00 00 00 * * *', function() { /* * Runs every day * at 00:00:00 AM. Run Cron Job every 45 minutes with Node-Cron. I'm using  Your script will be called every 15 minutes. The script then needs to check if it is 45 minutes. since it was last run (by means of a counter, timestamp, etc.) and only continue if it is at the 45 minute interval.

you can use node-reel which is more readable, straight forward and awesome 😉.

const reel = require('node-reel')

reel().call(() => {
    console.log(Date.now());
}).everyFortyFiveMinutes().run()

https://github.com/shakee93/node-reel

crontab every 30 minutes, An easy to use editor for crontab schedules. “At every 30th minute. Crontab every 30 minutes is a commonly used cron schedule. Cron job failures can be disastrous! We created Cronitor because cron itself can't alert you if your jobs fail or  Cron job cannot be used to schedule a job in seconds interval. i.e You cannot schedule a cron job to run every 5 seconds. The alternative is to write a shell script that uses ‘sleep 5’ command in it. Create a shell script every-5-seconds.sh using bash while loop as shown below. $ cat every-5-seconds.sh #!/bin/bash while true do /home

Running Cron Jobs in Node.js, In Node.js cron jobs can be setup using an external module known as Similarly to run a cron job every hour, setting the minute field to 0 will task will be executed at 45th and 50th minute of each hour cron.schedule('45,50  I'm looking to add a crontab entry to execute a script every 30 minutes, on the hour and 30 minutes past the hour or something close. I have the following, but it doesn't seem to run on 0.

Run a cron command every 15 minutes, This brief post looks at how to run a cron command every 15 minutes. will run every hour of every day on the hour, and at 15, 30 and 45 minutes past the hour. Run crontab job every minute on a Linux or Unix-like system. Running crontab (cron jobs) Every 10 Minutes. Cron Job Script Execution on the Last Day of a Month. Execute / Run crontab (cron jobs) every 1 minute. Ubuntu create cron.log file. Posted by: Vivek Gite. The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and

Cron Example Schedules, Examples of cron expressions for configuring time schedules and #node #linux a cronjob can only be scheduled to a minimum interval of 1 minute. If we leave every value as a wildcard it will execute after every minute. 17. Run a job every 6 months: 0 0 1 */6 * <command-to-execute> This cron job will start at 00:00 on day-of-month 1 in every 6th month. 18. Run a job every year: 0 0 1 1 * <command-to-execute> This cron job will start at 00:00 on day-of-month 1 in January. We can also use the following strings to define job.

Comments
  • It's not "every 45 minutes" but "every hour at 45".
  • tested this out, but it seems to run every second as well, which makes sense because of the first * When started at 17:50:18 it runs at 18:00:01 18:00:02 etc I'm going to try 00 in place of the first *
  • got it to work with a slight adjustment to the seconds field, here's the pattern; 0 */45 * * * *
  • If you can make the adjustments, I'll mark this answer as the accepted one.
  • @elimence: Consider whether it would be fairer to accept an answer to the question you actually asked, rather than one that matches the string in your question that you very specifically said didn't meet your requirements. There's nothing wrong with changing your mind about what you wan to do, but we're not mind readers. (BTW, would running the command every 30 minutes meet your revised requirements?)
  • I'm using a library called node-cron, all it requires from me is the right cron pattern. I don't think I can write scripts to work with it, if thats possible, then I don't know how. heres a link github.com/ncb000gt/node-cron
  • Sorry, I don't use node-cron. Never heard of it. The method above is for cron. Maybe node-cron has some additional syntax that cron doesn't have. I've met a similar problem, and have read the manual of crontab. I don't think it's possible for cron to do things like "every two weeks" or "every 45 minutes". So, writing a script as a wrapper to check whether to run seems to be the only choice.
  • I think you probably have the right idea. But since node-cron schedules execution of JavaScript code, not commands, the OP will need to write a JavaScript function that checks whether it should run.