Cron not working as expected - cron

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.

Related

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/

Run cron job every minute during specific hour during 30 minutes

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

Set cron job issue

I am first time trying to set cron job in my linux server. I want to set every 10 mins my file will run.
The cron works fine but the problem is that the cron run as following
00:00 00:10 00:20
but i want it in this way
00:05 00:15 00:25
If you have Vixie cron (the most common implementation these days), you can use this syntax:
5-55/10 * * * * command
where 5-55 specifies a range of minutes and /10 says to run once every 10 minutes.
If not, just enumerate all the times you want it to run:
5,15,25,35,45,55 * * * * command
Running man 5 crontab should show you the documentation. (man crontab will show you the document for the crontab command; man 5 crontab describes the file format.)
Reading the manual page you need an entry in your crontab file such as
5,15,25,35,45,55 * * * * <script path>
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
Check out this link
Easy to remember format:
* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Resources