Cronjob to run every 30 minutes - shell

I want to set a cronjob entry that runs a script every 30 minutes from 9:00 to 18:00 but I do not want it to run at 18:30. The script should run for the first time at 9:00 and for the last time at 18:00. Is this possible?

Yes, it is possible; cron itself can't solve the task, but it is possible using additional shell command:
*/30 9-18 * * * root [ $(date +%H%M) = 1830 ] || your_command
your_command will be executed if and only if the current time is not equal to 18:30

You might need to have two entries:
0,30 9-17 * * * /script
0 18 * * * /script
Alternatively, you could modify your script to check if it's close to 18:30 or not, and exit early if so.

Related

Schedule cron from 10PM to 1AM every half an hour

I am looking to schedule a cron from 10PM to 1AM(both inclusive) every half an hour .
I tried this */30 22-0 * * *
doesn't seem to work after 11:30 PM
or to be specific this works till 11:59 PM I guess.
Cron doesn't always provide the syntax to specify the times you want in a single line, but there's usually a workaround using two lines (or sometimes more).
Based on your description, apparently a range whose upper bound is smaller than its lower bound doesn't wrap around; rather it just seems to extend to the end of the day/hour/whatever. In your case, 22-0 apparently represents hours 22 and 23, and presumably 22-5, for example, would mean the same thing. (The man page is unclear on this.)
This should do the trick, though I haven't had a chance to test it:
*/30 22-23 * * * <command> # 22:00, 22:30, 23:00, 23:30
*/30 0 * * * <command> # 00:00, 00:30
0 1 * * * <command> # 01:00
Based on the other answer: You can make the crons one line less by combine records for 22-23 and 0 hour:
*/30 0,22-23 * * * <command>
0 1 * * * <command>
In some UNIX operating systems this may not work and you should explicitly mention the hours and minutes:
0,30 0,22,23 * * * <command>
0 1 * * * <command>

Is it possible to ensure that Laravel jobs actually run at round times?

I want to perform certain job exactly at round times, precisely every 30 minutes, for example:
- 00:00
- 00:30
- 01:00
- ...
- 12:00
- 12:30
- 13:00
- ...
In the Kernel.php, I have this job...
$schedule->command('mycommand:sender')
->everyThirtyMinutes();
... and in in the crontab, I have this command...
* * * * * cd /www/webapp && php artisan schedule:run >> /dev/null 2>&1
Apparently everything is ok, but if I stop the service or restart the server, this instructions, either in Kernel or even inCrontab, is correct for, for example, the server or service became available, at "12:29", I know the command will execute from "minute to minute", but "something" from these instructions will know that the next execution "should" be at 12:30 or the way it is, will run "30 minutes" after 12:29, therefore, 12:59?
Although it may seem irrelevant, but I have tasks in my system, that the needs to perform at these "round times", because the task "execution time" determines what will be performed.
Add this instead ->everyThirtyMinutes();
cron("*/30 * * * *")
This will be execute from now:
at 2019-12-04 18:00:00
then at 2019-12-04 18:30:00
then at 2019-12-04 19:00:00
then at 2019-12-04 19:30:00
then at 2019-12-04 20:00:00
Instead of run in cron every minute and check the logic in php why do not make cron to run every 30 minutes?
0,30 * * * * cd /www/webapp && php artisan schedule:run >> /dev/null 2>&1

I want schedule a task for every 24 hours by using cron expression settings

I want to schedule a method to run every 24 hours and with the settings I have it is executing every 24 minutes.
I have referred below URL's which has different suggestions
Link 1 suggests <second> <minute> <hour> <day-of-month> <month> <day-of-week> <year> <command>
Link 2 suggests minute hour day(month) month day(week)
Below are the cron settings put in the application.yml of my Spring Boot application.
cron:
job:
expression: 0 0 23 * * ?
Could someone help on what are the correct source of information and what can be the settings with the requirements at hand.
0 0 * * *
This will run job at 12:00 am every day
If you run the scheduled job in spring the record must be as mentioned in first link:
0 0 23 * *
This will run the job at 23:00:00 every day
0 0 0 */1 * *
I am using this command to run once everyday. You can also use
0 0 0/24 * * *
to run once every 24 hours

Execute job in Jenkins every X minutes and in a time range

I would like to execute a job in Jenkins with a cron every 15 minutes between a time range.
I tried with this:
15 8-19 * * 1-5
But it execute hourly. I want this:
Every 15 minutes From 8AM to 7PM and from Monday to Friday.
From the Jenkins' cron syntax:
* specifies all valid values
M-N specifies a range of values
M-N/X or */X steps by intervals of X through the specified range or whole valid range
To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible.
According to the rules above you can use the following:
H/15 8-19 * * 1-5
If I under Stand Your question all you need is something like below :
*/15 4,7 * * * /bin/sample >/dev/null 2>&1
i use crontab generator Online to get crontab configuration
*/15 8-18 * * 1-5
This will give you what you want, but the last execution will be at 18:45.
*/x means 'execute once in a given 'x' minutes/hours/etc

Cron job on Magento doesn't work properly

I have a problem with Magento cron expression. It works fine with minutes:
<crontab>
<jobs>
<namespace_module_cron>
<schedule>
<cron_expr>*/15 * * * *</cron_expr>
</schedule>
<run>
<model>namespace_module/observer::myMethod</model>
</run>
</namespace_module_cron>
</jobs>
</crontab>
But it doesn't work when I set hours:
<cron_expr>0 1 * * *</cron_expr>
or
<cron_expr>0 */1 * * *</cron_expr>
I tried different time settings in admin panel. For now there are:
15
1
60
120
120
3000
P.S. Magento ver. 1.7.0.1
Update
I left every hour job (0 */1 * * *) for a day and it actually runs:
14:15
16:15
21:15
22:15
03:15
04:15
I've figured out what was wrong. It were settings (System/Configuration/System/Cron).
When I set up "Schedule Ahead for" to 60 it started to work properly (every hour and every day schedules).
For now schedule in database is appearing at 15:20 when I need to execute it 16:00.
Settings:
Generate Schedules Every: 15
Schedule Ahead for: 60
Missed if Not Run Within: 60
History Cleanup Every: 120
Success History Lifetime: 120
Failure History Lifetime: 3000
If you have the same problem, you should pay attention to first two settings: "Generate Schedules Every" and "Schedule Ahead for"
For every hour at 0 minutes (00:00, 01:00; 02:00 etc), you must put :
<cron_expr>0 * * * *</cron_expr>
I have defined the corn job like this.
03 16 * * *
when your cron.php runs at 16:02 o'clock then it will create only an entry about this cron job in database table cron_schedule and it will not run the cron job.
To run this cron job i need to run cron.php twice,
means after creating an entry in table you should run cron within 15 minitues, otherwise that entry is ignored.
So to run the cron job, you should run the cron.php periodically.
my cron job run every day at 16:03
and i run cron.php every after 10 minute
I know this is old, but it may still be relevant as I encountered something similar. How often is your cron.sh scheduled to run on your server. If the scheduler is set to every 60 minutes and it runs on the hour (12pm, 1pm 2pm... etc) and your Scheduled ahead time is set to 20 minutes (default i think), and your magento cron expression is, for example, 30 * * * *, or every hour on the half hour, you job will never run. Your cron.sh will only set up magento cron jobs up to 20 minutes ahead, and so the 12:30 job will not get scheduled, but since magento's cron.sh is set to run on the hour, it will never get scheduled. I suspect your original problem is something similar, because adjusting the "scheduled ahead" time past the time the magento cron should be scheduled fix an issue like this. Just something to look out for as well.

Resources