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
How to Delete a Newline If It Is the Last Character in a File
How to Run a Shell Script When a File or Directory Changes
Why Does a Jvm Report More Committed Memory Than the Linux Process Resident Set Size
Hello, World in Assembly Language With Linux System Calls
How to Determine Whether a Given Linux Is 32 Bit or 64 Bit
How to Find Out Line-Endings in a Text File
Makefiles With Source Files in Different Directories
How to Build & Install Glfw 3 and Use It in a Linux Project
How to Run a Perl Script as a System Daemon in Linux
How to Get Terminal'S Character Encoding
Avoid Gnome-Terminal Close After Script Execution
How to Make an Executable Elf File in Linux Using a Hex Editor
How to Instruct Cron to Execute a Job Every Second Week
How to Run a Program With a Different Working Directory from Current, from Linux Shell
How to Use the Lines of a File as Arguments of a Command
How to Open a New Tab in Gnome Terminal from Command Line