Cron pattern for multiple time with *AND* - linux

I want to create a cron pattern for the expression Every day at 7 PM, 8:30 PM and 9:45 PM.
Is it possible to create one cron pattern for it or I will have to write 3 separate ones?

With cron alone you would have to create 3 separate cron jobs. However, here's a possible workaround: you can create a single cron entry for 7 PM, such as:
0 19 * * * /folder/script
And then create a script that "sleeps" the time you need before calling the other commands at 8:30 PM and 9:45 PM, such as:
#!/bin/bash
nohup my_command_here &
#sleep until 8:30 PM - 90 minutes or 5400 seconds
sleep 5400
nohup my_command_2_here &
#sleep until 9:45 PM - 75 minutes or 4500 seconds
sleep 4500
nohup my_command_3_here &
exit

Related

How to run a cron job which runs every 4 hrs starting at 4:30 pm and shouldnt run between 2 am and 6am

I have tried creating a cron expression starting at 4 pm running every 4 hrs but not sure how to start at 4:30.
Below is the expression:0 0 16/4,20,0,8,12? * * *

Running a cron at 4 am and 4 pm

The following cron expression cron(0 14 ? * MON-FRI *) basically runs something 4:00 pm from Monday to Friday.
I am wondering if it is possible to modify the expression so I can run something at 4:00 am and 4:00 pm every Monday to Friday.
Use this crontab line to run command_name at 4:00 and 16:00 (4 AM and 4 PM) Monday-Friday:
0 4,16 * * 1-5 command_name
From crontab manual:
The time and date fields are:
field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sunday, or use names)
Your Cron job description looks different from the general crontab. But to give you an idea of how to achieve what you're looking for:
Edit cron-table. Choose your editor.
crontab -e
Add 2 lines cron jobs.
* 4 * * 1-5 /usr/bin/...# Your command goes here 04:00 am.
* 16 * * 1-5 /usr/bin/...# Your command goes here 04:00 pm.
4PM (16:00): 0 16 * * MON-FRI
See crontab guru
"At 16:00 on every day-of-week from Monday through Friday.”
4AM &4 PM (4:00 & 16:00): 0 4,16 * * MON-FRI
See crontab guru
β€œAt minute 0 past hour 4 and 16 on every day-of-week from Monday through Friday.”

Cron job should run every 15 minutes , but it should NOT run between 9:00 (AM) to 10:00 (AM)

How to run a Cron job every 15 minutes , but it should NOT run between 9:00 (AM) to 10:00 (AM).
You may try:
* 0,15,30,45 0-9,10-23 * * ?
The above CRON says to run on the hour, 15, 30, and 45 minutes past the hour, from midnight to 9am, and from 10am to midnight. This excludes 9am-10am which was your requirement.

Scheduling scripts with variable frequency

I want to run a python script on a ubuntu 14.04 server with following frequency:
Monday to Friday:
From 0800 hrs to 1600 hrs: Run once every hour
From 1600 hrs to 2300 hrs: Run once every 30 minutes
Saturday and Sunday:
From 0800 hrs to 2300 hrs: Run once every two hours
At other times, don't run
Is this possible with cron? If not, can anybody suggest some alternative?
As suggested in the comments, adding these cron entries will do:
(Lines starting with # are comments)
# monday to friday, 8 am to 4 pm, once every hour
0 8-16 * * 1-5 <command>
# monday to friday, 4 pm to 10 pm, twice every hour
0,30 17-22 * * 1-5 <command>
# saturday to sunday, 8 am to 11 pm, once every hour
0 8-23 * * 0,6 <command>

Running a cron job every 2:30 on every day?

If I creating cronjob to running for every 2:30 the command will run? (It mean, my cron will running after 90 minutes for every hours.)
the command like: 30 */2 * * * /command/xxx => that's right?
Please help?
Your cron expression 30 */2 * * * will run the command every 2 hours at 30 mins past the hour i.e.00:30, 02:30, 04:30, 06:30 and so on.
If you want to run your command at intervals of two and a half hours i.e. 00:00, 02:30, 05:00, 07:30 and so on, you need to set up two crons:
0 0-20/5 * * * runs at 0 mins past the hour, every 5 hours between 00:00 and 20:00 inclusive i.e. 00:00, 05:00, 10:00, 15:00 and 20:00
30 2-22/5 * * * runs at 30 mins past the hour, every 5 hours between 02:00 and 22:00 inclusive i.e. 02:30, 07:30, 12:30, 17:30 and 22:30
On the other hand, if you want to run your command only once every day at 02:30 use 30 2 * * *.
sudo crontab -e
and then add this:
30 2 * * * /enter/your/command

Resources