Difference between */1 * * * * and * * * * * in CRON - unix

I am not sure if there is difference between following CRON expressions:
* * * * *
and
*/1 * * * *
I tested both expressions in online CRON tester and it looks like both are doing the same thing - it executes given command every minute. The first one is pretty straightforward, but is there a real difference between them? Or is it only matter or preference and code readability? Thanks a lot for your answers.

Related

CRON: Difference between "At minute 0" and "Every 60 minute"

What is the difference between "At minute 0": 0 * * * *
and "Every 60 minute": 0/60 * * * *
Are these two represent the same schedule? I need to start job at the beginning of every hour and have found both in different sources, this is confusing
They are the same. If you divide 0 to 60 you will get 0. And the canonical records which will work in UNIX and linux is:
0 * * * * command
because many (if not all) Unix OS do not understand records like something/other in cron

appending log to a file in unix but with different name each day

i am appending the output of a cron job into a file like below
10,20,30,40,50 * * * * /home/mydir/shellScript.sh >> /home/mydir/shellScript.log 2>&1
but the file size is keep on increasing, i want to do either of the below things.
1)create a new file after reaching certain size
2)create a new file each day of its run
we need to maintain the file for at least 15 days due to audit reasons.can someone help on this,thanks in advance.
i solved using below:
10,20,30,40,50 * * * * /home/mydir/shellScript.sh >> /home/mydir/shellScript_`date +\%Y\%m\%d`.log 2>&1

Cron job setting,explanation

For cron job setting,I defined a job as below:
* */12 * *
What I had assumed that it means the cron job will run after every 12 hours,unfortunately found that its running more frequently,not sure how frequently but the output was large than expected.
Can any explain it simply,I went through different docs but it seems there are several way to set a single cron.
Can anyone explain it easily?
Btw I updated my cron for running every 12 hours like below:
* * 12 * * ?
Thanks in advance.
This line should run at 12AM and 12PM:
* 0,12 * * * /path/to/command
* */12 * * means run every minutes on 0 and 12. If you want to make it run once in those hours, put a number instead of the first star(*), such as
20 */12 * *
By the way, there should be 5 time fields in the cron job instead of 4 fields, so it should actually be
20 */12 * * *
I was searching for the same and I found this site very useful.
It will explain your cron job.
look at the below example:
*/15 * * * * cd ~/ecg;
Explanation: The command cd ~/ecg; will execute every 15 minutes of every hour on every day of every month.
15 09 07 03 * php abc.php
Explanation: The command php abc.php will execute at 9:15am on the 7th of March.

Cron expression - every 2 minutes between 6 and 21:28

I am using Quartz.Net and I am trying to come up with a CRON expression for:
Every 2 minutes between 06:00 and 21:30.
Is there such an expression?
this may help http://quartznet.sourceforge.net/tutorial/lesson_6.html,with this they are using frames:s, so go to Quartz.Impl.Triggers and then and then CronTriggerImpl there is a description of the possibilities
From what I understand from it it will be something like this
"0 0/2 6-21 * * ?"
This alone will not be sufficient in your case so you probably need a second one writen like this:
"0 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28 21 * * ?"
little long but as far as I can make up from the documentation this would be the only solution to your problem. But probably the solution of SenorAmor is nicer
I believe you'll need two commands. Try:
0 0/2 6-21 * * <command>
and
0 0-30/2 21 * * <command>

Any standard format to describe time ranges as String? Want to use it for opening hours

We want to use it for opening hours like...
Mo 11:00-13:00
Tue 9:00-18:00
Update Now required: Wed 8:00-11:30, Wed 12:00-17:00
We have a Ruby based server and deliver JSON and XML to the clients. We follow the ActiveResource pattern, so that we can use plug ins in our clients
That's our current proprietary approach:
"availabilities":[{"end_time":"00:00","weekdays":"0,1,2,3,4,5,6","start_time":"00:00"}]
cron format was designed specifically for this, including relative dates like "from midnight to 1 AM of the first Monday each month except December".
Edit: cron expressions for all examples:
* 11-12 * * mon
* 9-17 * * tue
* 8-10 * * wed
0-29 11 * * wed
* 12-16 * * wed
I would use the number of milliseconds since midnight. That's fairly standard, as in JavaScript and other languages you can easily add a number of milliseconds to a given time in order to get another time, or create a time-span object from a number of milliseconds.

Resources