Set cron job issue - cron

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)

Related

Bad hour in crontab file

I am trying to run a scheduled job via crontab in linux mint. For that, I am using the crontab -e command to edit a crontab file with the following information:
0 50 * ? * * * sh test.sh
After which I get the error:
"/tmp/crontab.XCXmSA/crontab":22: bad hour
errors in crontab file, can't install.
I tried searching but couldn't find anything that solved the problem. Tried a bunch of different times and still nothing. Any ideas?
You use totally wrong syntax. You add more stars. And questionmark which is not accepted there. Here is the syntax you search:
50 * * * * sh test.sh
And as mentioned in comments you cant have 50 as hour definition
And instead of using explicit shell add it in shebang and make the script executable
You put 50 as an hour. Hour should be in 0..23 range.
# For details see man 4 crontabs
# Example of job definition:
# .---------------- 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

How to set customised schedule in linux cron?

I'm in need to set a cron in crontab like, a php file should be called according to the below schedule
Mon-Fri, 9:00AM to 3:30 PM every one minute
I tried like below,
*/1 * * * * wget http://example.com/trail.php
Can someone help me how to create a cron for the above requirement?
Thanks,
Check the manpage of cron (man 5 crontab). You can do a lot of things, but there's no easy and simple way to achieve what you want. Probably the easiest is to use two entries:
* 9-14 * * * <command>
0-30 15 * * * <command>
You can use following pattern and code
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 9-14 * * 1,2,3,4,5 wget http://example.com/trail.php
0-30 15 * * 1,2,3,4,5 wget http://example.com/trail.php
Finally, got the obsolete solution.
*/1 9-14 * * 1-5 wget -O /dev/null example/alerts.php
0-30 15 * * 1-5 wget -O /dev/null example/alerts.php
making this work like a charm.
Thanks for the answering, learnt from #Smit Raval and #Ulrich Eckhardt.

How to specify a file to run everyday in crontab

I wants to run a file by everyday using crontab. But i have confusion on specifying the file in crontab. So, please suggest me to mention the file to run everyday ( start of the day, for example: 12:00 am ). Thanks in advance.
If by "file" you mean an executable shell script, then this will do:
00 00 * * * /path/to/the/executable/file.sh
It will run at midnight every day. You should enter this line in a file that will open when you invoke crontab -e command. Once you edit it, save and quit, and crontab will verify whether syntax you entered is correct, so watch the output in the shell.
Use the following format:
0 0 * * * command
check examples here
# minute, hour, day of month, month, day of week
* 12 * * * /home/mydirectory/myscript.sh
* 23 * * * /home/mydirectory/myotherscript.sh
58 23 * * * /home/mydrectory/two_minutes_to_midnight.sh
* 0 * * * /home/mydirectory/goodnight.sh
to make a crontab work, you can read an official doc, there are many of them, and depends on you operational system. But speaking od rules? i'll give some examples:
Common rules :
############################################################################
#
# * * * * * running command
# - - - - -
# | | | | |
# | | | | ----- day of week (0 - 7) (sunday =0 or =7)
# | | | ------- month (1 - 12)
# | | --------- day (1 - 31)
# | ----------- hour (0 - 23)
# ------------- minute (0 - 59)
#
###########################################################################
So if you want to call shell script that works with your files every "x" minutes you can make such a rule :
# work every two minutes
*/2 * * * * /usr/local/sbin/work_script.sh
also, between ranges:
# works every 5 minutes between 7 and 22 hours
*/5 7-22 * * * /usr/local/sbin/work.sh
You can use the below command to intialize the crontab entry to run it everyday.
Syntax : * 10 * * * /home/nagios/myscript.sh
Add the entry #crontab -e and save.
The above command will the command daily at 10 am in the morning.

CronTab - Not Working

I seem to be having problems with crontab, the following works correctly
* * * * * TERM="xterm";/usr/bin/lynx -dump http://myurl.com
However, when I try scheduling one in for every Sunday at 20:40
*/40 */20 * * 0 TERM="xterm";/usr/bin/lynx -dump http://myurl.com
It doesn't work, is there something wrong with my syntax? I actually used a generator to write this.
I'm running CentOS, the cronjob should visit a PHP page that then uploads to DropBox - visiting the URL via the browser works. I'm validating my results by checking the dropbox uploaded timestamp on the file.
UPDATE - For some reason, using CURL instead worked fine :)
Here's a cron syntax checker
It said
The command TERM="xterm";/usr/bin/lynx -dump http://myurl.com will execute every 40 minutes of every 20 hours on of every month.
Which isn't what you're wanting I think.
The slashes you are using make increments of ranges. See cron special characters
I recommend you read up on the cron syntax. You want:
40 20 * * 0
Explanation:
* * * * * command to be executed
^ ^ ^ ^ ^
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

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