How to Instruct Cron to Execute a Job Every Second Week

How to instruct cron to execute a job every second week?

How about this, it does keep it in the crontab even if it isn't exactly defined in the first five fields:

0 6 * * Tue expr `date +\%W` \% 2 > /dev/null || /scripts/fortnightly.sh

How to set cron job for bi-weekly (twice a week)

How about the following:

0 0 * * 1,4

This sets the day of week to Monday (1) and Thursday (4). You can choose any values 0–7 (both 0 and 7 are Sunday).

For a more readable crontab, you can also use names:

0 0 * * MON,THU

See also: How to instruct cron to execute a job every second week?

Cronjob every two weeks

AFAIK cron can't handle "every second week".

Instead, you could run it every Sunday at midnight and modify the script exit early if it's not one of the Sundays you want it to run.

If modification of the script is not possible, create a wrapper script that only calls the main script when it's a scheduled Sunday and call the wrapper from cron.

Crontab skip run once a week

Make it 2 lines:

0 0,8,16 * * 0-5 At minute 0 past hour 0, 8, and 16 on every day-of-week from Sunday through Friday.

And

0 8,16 * * 6 At minute 0 past hour 8 and 16 on Saturday.

You can change the day and hour which you want to skip, but there is no way to do this in 1 line as far as I know.

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.



Related Topics



Leave a reply



Submit