Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my /etc/crontab file I have:

# m h dom mon dow user  command
17 *  * * * root    cd / && run-parts --report /etc/cron.hourly
25 6  * * * root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6  * * 7 root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6  1 * * root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

I know what this does in practice but I don't understant the command lines.

Man "test" doesn't help at all:

test - check file types and compare values

Any help would be greatly appreciated

share|improve this question
up vote 7 down vote accepted

From FreeBSD's man test: [1]

 -x file       True if file exists and is executable.  True indicates only
               that the execute flag is on.  If file is a directory, true
               indicates that file can be searched.

So the cronjobs test if there is anacron installed [2] (i.e., there is an executable called anacron in the expected place) and run something if not - namely the scripts in the respective /etc/cron.* folders.

(1) Bash's builtin test has the same -x option

(2) Anacron is a cron replacement designed for computers that are not always running, i.e., if there's a job to be run weekly, it will be run weekly, relative to the uptime of the computer, which means it will not run every, say, friday, but every 24*7 hours of uptime. (Edit I got it all wrong, see comments)

share|improve this answer
That's not a very accurate description of what Anacron does. It doesn't measure uptime. It simply runs jobs whose scheduled run time occurred while the computer was off as soon as you turn the computer back on. Regular cron skips a job if the computer isn't on at the instant it was scheduled to run. – cjm Dec 5 '11 at 17:27
oh, then I got it wrong (or mixed it up with what fcron does? there was another cron replacement...). thanks for the heads-up – sr_ Dec 5 '11 at 18:07
@cjm afaik anacron needs its own config-files. So you have to explicitly configure anacron-jobs. – Nils Dec 5 '11 at 20:50
@Nils, I wasn't trying to imply otherwise. I'm just pointing out that "every 24*7 hours of uptime" is completely wrong. Anacron's schedule is based on calendar time, not uptime. – cjm Dec 5 '11 at 20:56

You may be familiar with [ -x <filename> ]. test -x <filename> does the same thing, test if this file exists and is executable.

share|improve this answer

As quoted in the man page, test is much similar to eval, it evaluates a conditional expression expr and exits with the return status. Often encountered cases, test is used to determine the type of the file as an expression in which cases it is used to check for a return of either true or false case. In your crontab, test -x filename, where filename is used as expression. This is also equivalent to [ -x filename ]. This will return true if the file is present and is also executable(bit is set). man test gives definite details of the varied options for type to evaluate the conditional expressions on the files and other valid shell expressions.

For example:

test -1 -gt -2 && echo yes would print yes.

test 0x100 -eq 1 error--> test: integer expression expected before -eq

share|improve this answer
Do you mean the eval statement in sh/ksh/bash/zsh? – Arcege Dec 5 '11 at 12:22

Your Answer


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.