Linux Task Schedule to Hour, Minute, Second

Run a cron job every second minute of every hour

If your operating system is FreeBSD you could use the @every_second for example:

@every_second  /var/www/html/cron.php

For other systems, this could work:

Somethinig every hour:

@hourly /var/www/html/cron.php

Or every 45 minutes:

*/45 * * * * /var/www/html/cron.php

From man 5 crontab:

       string          meaning
------ -------
@reboot Run once, at startup of cron.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly Run once a week, "0 0 * * 0".
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
@hourly Run once an hour, "0 * * * *".
@every_minute Run once a minute, "*/1 * * * *".
@every_second Run once a second.

Also, check this a reference: https://crontab.guru/

In case the system you are using doesn't support the @every_second you could give a try to something like:

* * * * * /var/www/html/cron.php
* * * * * (sleep 30; /var/www/html/cron.php)

Basically, they run at the same time (every minute) but one will wait for 30 seconds before starting, so /var/www/html/cron.php will be called every 30 seconds.

crontab run every 15 minutes between certain hours

Your command is fine!

To run from 7.00 until 19.45, every 15 minutes just use */15 as follows:

*/15    07-19        *     * *     /path/script
^^^^ ^^^^^

That is, the content */15 in the minutes column will do something every 15 minutes, while the second column, for hours, will do that thing on the specified range of hours.

If you want it to run until 19.00 then you have to write two lines:

*/15    07-18        *     * *     /path/script
0 19 * * * /path/script

You can have a full description of the command in crontab.guru: https://crontab.guru/#/15_7-19___

Scheduling Python Script to run every hour accurately

Maybe this can help: Advanced Python Scheduler

Here's a small piece of code from their documentation:

from apscheduler.schedulers.blocking import BlockingScheduler

def some_job():
print "Decorated job"

scheduler = BlockingScheduler()
scheduler.add_job(some_job, 'interval', hours=1)
scheduler.start()

Run CRON job everyday at specific time

Cron utility is an effective way to schedule a routine background job at a specific time and/or day on an on-going basis.

Linux Crontab Format

MIN HOUR DOM MON DOW CMD

Sample Image

Example::Scheduling a Job For a Specific Time

The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.

Please note that the time field uses 24 hours format. So, for 8 AM use
8, and for 8 PM use 20.

30 08 10 06 * /home/yourname/full-backup
  • 30 – 30th Minute
  • 08 – 08 AM
  • 10 – 10th Day
  • 06 – 6th Month (June)
  • *– Every day of the week

In your case, for 2.30PM,

30 14 * * * YOURCMD
  1. 30 – 30th Minute
  2. 14 – 2PM
  3. *– Every day
  4. *– Every month
  5. *– Every day of the week

To know more about cron, visit this website.

Run cron job every 2 hours In the X minute

Put your desired minute in the minute column, and then use */2 in the hour column to get it to run every two hours.

24 */2 * * * <your command>



Related Topics



Leave a reply



Submit