Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
The link goes to Ubuntu wiki. Why not trust it? –  papukaija Feb 12 '11 at 14:58
1  
@papukaija I generally agree, though it is possible that the information on the Ubuntu wiki could be outdated or even wrong (since it can be edited by any registered user). –  belacqua Feb 14 '11 at 6:11
add comment

2 Answers 2

up vote 5 down vote accepted

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 )
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.