Cron job at specific interval of minutes - cron

I need to run a cron job in linux at 20 minutes interval everyday. The most important thing is, it must be on specifically 10th, 30th and 50th minutes.
I think I need to run 3 cron jobs as :
10 * * * * /path_to_script
30 * * * * /path_to_script
50 * * * * /path_to_script
Is it possible to meet this requirement using a single cron job ?

10,30,50 * * * * /path_to_script
or
10/20 * * * * /path_to_script

aggregate all scripts in one with sleep(1200) time separator
#script
#!/bin/bash
./wayto/script1;
sleep(1200);
./wayto/script2;
sleep(1200)
./wayto/script3;
and make one job in cron via crontab -e
10 * * * * /bin/bash /way/to/script

Related

Properly Defining DAG Schedule Interval

Problem: We're having difficulties having a DAG fire off given a defined interval. It's also preventing manual DAG executions as well. We've added catchup=False as well to the DAG definition.
Context: We're planning to have a DAG execute on a 4HR interval from M-F. We've defined this behavior using the following CRON expression:
0 0 0/4 ? * MON,TUE,WED,THU,FRI *
We're unsure at this time whether the interval has been defined properly or if there are extra parameters we're ignoring.
Any help would be appreciated.
I think you are looking for is 0 0/4 * * 1-5 which will run on 4th hour from 0 through 23 on every day-of-week from Monday through Friday.
Your DAG object can be:
from airflow import DAG
with DAG(
dag_id="my_dag",
start_date=datetime(2022, 2, 22),
catchup=False,
schedule_interval="0 0/4 * * 1-5",
) as dag:
# add your operators here

Cron is running 2 times node-cron

I installed node-cron library and configured 2 crons in the same file to run at different intervals. The first cron runs every 45 seconds and the second cron runs every 60 seconds, it works perfectly. The problem happens when the 60-second cron is run, automatically the 45-second cron is also run again (notice that the difference is 15 seconds). Why does this happen?
const cron = require('node-cron');
cron.schedule('*/45 * * * * *', async () => {
console.log('running 45 seconds')
})
cron.schedule('*/60 * * * * *', async () => {
console.log('running 60 seconds')
})
Cron will run this at "every 45th second, of every minute...".
Starts at 0 seconds, then at 45 seconds.
Starts at 0 seconds, then at 45 seconds.
This will be noticeable whenever the */x interval isn't divisible by the parent time unit (seconds in a minute, minutes in an hour etc).
For example, */17 * * * * *
2021-08-17T23:07:00.230Z running */17 seconds
2021-08-17T23:07:17.273Z running */17 seconds
2021-08-17T23:07:34.302Z running */17 seconds
2021-08-17T23:07:51.344Z running */17 seconds
2021-08-17T23:08:00.374Z running */17 seconds
2021-08-17T23:08:17.424Z running */17 seconds
2021-08-17T23:08:34.467Z running */17 seconds
2021-08-17T23:08:51.494Z running */17 seconds
2021-08-17T23:09:00.525Z running */17 seconds
2021-08-17T23:09:17.564Z running */17 seconds
To run something on a 45 second timer via cron, you probably need a task every 15 seconds then some logic to check if the previous run was >= 45 seconds ago.

Airflow schedular doesnt pick the DAG on specific schedule_interval config( 0 8 * * 5)

I want to add schedule(Every Friday at 8:00 AM) to the DAG. Below is my config for the DAG:
DAG CONFIG:
args = {
'owner': 'airflow',
'start_date': airflow.utils.dates.days_ago(20),
'depends_on_past': False,
'email': [failure_email],
'email_on_failure': True,
'email_on_retry': True,
}
dag = DAG(dag_id='dag_airflow_delete_logs_less_than_40_days',
default_args=args,
schedule_interval='0 8 * * 5',
max_active_runs=1)
After adding the schedule to DAG, airflow didn't pick up the dag on Friday 8:00 AM UTC. I removed '5' from the crontab schedule and configured as '0 8 * * *' it worked fine for every day.
I also tried different ways to schedule interval using crontab format, still no luck:
(0 8 * * 5)
(0 8 * * FRI)
I don't understand why it's not working when I specify the day in the interval? Please let me know your thoughts. Thanks in advance!
Note: I used below websites to check the crontab configs .
1) https://crontab.guru/
2) http://corntab.com
Attached Screenshot for the DAG Runs: http://tinypic.com/view.php?pic=5x4x3d&s=9#.W-RSjLpFyFQ

Cron tab scheduling for different timings on different days

I need to schedule a job from Mon-Thur at 7pm and on Friday i need it to be scheduled at 11pm. I am using Airflow and need the cron tab notation like
0 19 * * Mon-Thu
Any suggestion are welcome.
Thank you
Regards,
CJ
You can create your dag as:
dag = DAG("Your_dag", default_args=default_args, schedule_interval="0 19 * * 1-4")
You could do something like this:
schedules = {
'M-Th': '0 19 * * 1-4',
'F': '0 23 * * 5',
}
for name, schedule in schedules.items():
globals()[name] = DAG('<base_dag_name.' + name, default_args=default_args, schedule_interval=schedule)
This will create two DAGs from a single file. DAGs need to be in the global scope to be recognized by Airflow.

How to run cron job before midnight to after midnight (over midnight)?

How can I create a cron job that runs from 19:00 to 5:00? This doesn't work:
* 19-05 * * ....
Should I use two jobs? 👇
* 19-23 * * ....
* 1-5 * * ....
On some distributions you can:
* 19-23,0-5 * * *
Check here: https://unix.stackexchange.com/questions/67158/crontab-entry-with-hour-range-going-over-midnight
I can confirm that 19-23,0-5 works on Ubuntu server 16.04.
yes, you need to lines:
* 19-23 * * ....
* 0-05 * * ....
Yes, you will end up to split it up, like this:
*/10 22-23 * * * logger "brooks was here"
*/10 00-05 * * * logger "brooks was here after midnight"

Resources