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.

Many a time and oft, crontab scripts are not executed as expected. There are numerous reasons for that, for example: wrong crontab notation, permissions, environment variables and many more.

This community wiki aims to aggregate the top reasons for crontab scripts not being executed as expected. Write each reason in a separate answer.

Please include one reason per answer - details about why it's not executed - and fix(es) for that one reason.

Please write only cron-specific issues, e.g. commands that execute as expected from the shell but execute erroneously by cron.

share|improve this question
add comment

closed as too broad by jokerdino Oct 22 '13 at 17:34

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

32 Answers

When a task is run within cron, stdin is closed. Programs that act differently based on whether stdin is available or not will behave differently between the shell session and in cron.

An example is the program goaccess for analysing web server log files. This does NOT work in cron:

goaccess -a -f /var/log/nginx/access.log > output.html

and goaccess shows the help page instead of creating the report. In the shell this can be reproduced with

goaccess -a -f /var/log/nginx/access.log > output.html < /dev/null

The fix for goaccess is to make it read the log from stdin instead of reading from the file, so the solution is to change the crontab entry to

cat /var/log/nginx/access.log | goaccess -a > output.html
share|improve this answer
add comment

I once was working on a shared server with lots of restrictions.

All the answers here (PATH, SHELL, bash -c,...) could not get my script to work in the crontab.

It did work perfectly when I put the command in a little script file with the PATH, SHELL, and shebang rather than in the crontab itself. I did have to change the permissions to 700.

share|improve this answer
add comment

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