Run cron job every minute during specific hour during 30 minutes - cron

I know I can set up cron for every minute, like
* * * * *
for once a day AFAIK it would be (lets say on 2am)
0 2 * * *
for every 30 minutes
0,30 * * * *
Now, is it possible to run cron job every minute, but during 30 minutes, once a day. For example I need the cron to run every day from 2am to 2:30, and during that time every minute.
thanks

Yes, sure. Use this:
0-30 2 * * *
^^^^ ^
| |
| on hour 2
on minutes from 0 to 30
Remember the format is as follows:
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed

Related

Crontab to run at two hours out of the day, but for one of those hours exclude certain days of the week

I need to change the below schedule to exclude Tuesday and Thursday for only the 2nd hour.
0 2,20 * * *
I want to run a job everyday at 2 am and 8pm, but on Tuesdays and Thursdays exclude the 2 am job.
The easiest answer is going to be two separate entries in your crontab:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
* 2,20 * * 0,1,3,5,6 root /path/to/command.sh
* 20 * * 2,4 root /path/to/command.sh
Make sure that command.sh isn't in an /etc/cron.* folder.
I think all you need is
0 2,20 * * 1,3,4,6,7
the numbers at the end are the days of the week. O being Sunday.

How can i run cron-job every 1 hour in Ubuntu 14.04?

I want to run a cron for every 1 hour.
What i tried :
0 */1 * * * /home/username/test.sh
0 * * * * /home/username/test.sh
But, i am not sure, which one is right ?
Can you please help me to decide . which one i should use?
This is the way to set cronjob on ubuntu for every 1 hour
0 * * * * or you can put it in cron.hourly directory
For more details you can refer link:
https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job
# Use the hash sign to prefix a comment
# +---------------- minute (0 - 59)
# | +------------- hour (0 - 23)
# | | +---------- day of month (1 - 31)
# | | | +------- month (1 - 12)
# | | | | +---- day of week (0 - 7) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
#--------------------------------------------------------------------------
* */1 * * * root /bin/sh /home/username/test.sh

Cronjob understanding: how to run every day from 8-10 till 10-30 every 10 and 30 minute?

I need to run task every day from 8-10 till 10-30 every 10 and 30 minute:
start at 8:10 ->
8:30 ->
9:10 ->
..
-> 10:30 finish
I have such cronjob:
10,30 8,9,10 * * *
will it be correct?
Yes, it is fine!
You can check it in http://crontab.guru/#10,30_8,9,10_*_*_*
Since you want to run it in an interval of hours, you can also say 8-10 to match hours from 8 to 10:
10,30 8-10 * * *
For your future reference, this is the format for cronjobs:
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
A briefly shorter version would be
10,30 8-10 * * *
but yes, your version also works fine.
If you want to play around a bit, you can try crontab.guru.

Cron Scheduling format guidance

I want to run a cron every 30 seconds between 00:00 and 11:55, every day, every month, any day of the month.
Is the following correct?
0/30 * 0-11 **
The format is as follows:
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
So if you want to run every minute between 00.00 and 11.55, every day, every month, any day of the month, you need to combine two different lines:
* 0-10 * * * command
0-55 11 * * * command
Note that to run every 30 seconds you can use the trick described in Running a cron every 30 seconds.
You can try to run your script every 30 seconds using the following:
* 0-11 * * * (sleep 30; /path/to/executable)
So your crontab should looks like
* 0-11 * * * /path/to/executable
0-54 0-11 * * * (sleep 30; /path/to/executable)
Both command lines will be executed at the same time, but the second one will do a 30 seconds sleep before executing your command.
You can try to validate your cron statement with decoder
One of them you can find by the link: http://cronwtf.github.io/

Cron not working as expected

I have an interesting problem with a cron job. I'm on a server with Cent OS and we're using Vixie cron. All this is very straighforward and i have a backup job that i want to run once every day at 01.00, so i created this simple crontab entry:
* 1 * * * /path/to/my/simpleJob.sh
What happens is this: at 01.00.02, the job runs as expected. Then cron (or something) continues to run the job every minute. Can anyone out there help me out? I have no idea what might be the root cause for this.
/M
The format is:
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
So in your case being
* 1 * * * /path/to/my/simpleJob.sh
it means at hour 1, any minute.
To have it working just at 1.00, change it to:
0 1 * * * /path/to/my/simpleJob.sh
The CronSandbox at Dataphyx lets you play about with the date/time values - you see a schedule of runtimes for whatever combination you put in.

Resources