How to interpret this crontab command?

I know that if I wrote in crontab -e following command 01 04 * * * somecommand then it will run somecommand at 4:01am on every day of every month.

What happens if I wrote * * * * * somecommand? Will it run somecommand every single minute? Will this syntax work also?

And it is possible to use special strings like @reboot, @daily, etc as it is explained here. At what time of the day somecommand will be executed if I write @daily somecommand command?

2

2 Answers

This will run your command every minute. It is valid syntax.

Here are the gory details from info crontab :

 The first five fields shall be integer patterns that specify the following: 1. Minute [0,59] 2. Hour [0,23] 3. Day of the month [1,31] 4. Month of the year [1,12] 5. Day of the week ([0,6] with 0=Sunday) Each of these patterns can be either an asterisk (meaning all valid values), an element, or a list of elements separated by commas. An ele‐ ment shall be either a number or two numbers separated by a hyphen (meaning an inclusive range). The specification of days can be made by two fields (day of the month and day of the week). If month, day of month, and day of week are all asterisks, every day shall be matched. If either the month or day of month is specified as an element or list, but the day of week is an asterisk, the month and day of month fields shall specify the days that match. If both month and day of month are specified as an asterisk, but day of week is an element or list, then only the specified days of the week match. Finally, if either the month or day of month is specified as an element or list, and the day of week is also specified as an element or list, then any day matching either the month and day of month, or the day of week, shall be matched.

The article you linked to looks like a good one. It's giving you some good examples and it's actually easier to read than the man-page excerpt I provided here.
You should be able to use the syntax it talks about.

According to my crontab, @daily runs at 6:25 AM .

$ grep daily /etc/crontab
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
0

You can also specify odd frequencies by using forward slashes within each column.

* */2 * * * foo

will execute foo at hours that are divisible by 2, viz: 12 AM, 2 AM, 4 AM, ... ,10 PM, 12 AM.

Remeber this command

*/1 * * * * env > /home/yourUser/env.out

will output the crontab environment's environment variables for you to work with, in your crontab. You can use maybe variables like ${HOME}, ${SHELL} to make the script cleaner and maybe use the script on another machine.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like