've been puzzling over cronjobs for the last few hours. I've read documentation and examples. I understand the basics and concepts, but haven't gotten anything to work. So I would appreciate some help with this total noob dilemma.

The ultimate goal is to schedule the execution of a django function every day. Before I get that far, I want to know that I can schedule any old script to run, first once, then on a regular basis.

So I want to: 1) Write a simple script (perhaps a bash script) that will allow me to determine that yes, it did indeed run successfully, or that it failed. 2) schedule this script to run at the top of the hour

I tried writing a bash script that simple output some text to the terminal:

echo "The script ran"

Then I dropped this into a .txt file

MAILTO = *****.******@gmail.com
05 * * * * /home/vadmin/development/test.sh

But nothing happened. I'm sure I did many things wrong. Where do I start to fix all of this?


I don't know if you'll actually be able to see the cron output on the screen like that.

I bet if you put

echo "the script ran" >> /home/vadmin/file.txt

In your job, verify that cron is running and the crontab is installed correctly (as the other answers suggested), it will run as expected.

The cron you specified won't run everyday though, it will run at 5 after each hour.


Is your cron daemon actually running? Check the process table.

There might also be an issue with emailing the results - check the logs of crond and your local mailserver for that.

  • Oh, misread the txt-file part :) – user22656 Dec 22 '10 at 16:50
  • how do I check the crond/mailserver logs? – Ed01 Dec 22 '10 at 17:32
  • You didn't specify your OS, but my cron results on Ubuntu get logged to /var/log/syslog. On other platforms I've seen it put in /var/log/cron. – Cory J Dec 22 '10 at 17:50

The lines you dropped into a .txt file need to be added to a crontab.

Best practices indicate you don't edit the crontab file directly, but use the crontab -e command which will open the crontab in an editor, allow you to edit/save it, check it for syntax errors, and save it safely.

Also, a quirk of cron that might exist on your system is that if the last line in the file isn't a blank line, cron ignores the preceding line. Make sure you add at least one blank line at the end of your crontab.

  • yep, should have mentioned, I used crontab test.txt to add the .txt. It shows up in crontab -l. I will try the blank line bit. – Ed01 Dec 22 '10 at 17:17
  • @Ed01: Be aware that crontab filename will overwrite the previous contents and should only be used if you're sure you want them replaced. – Dennis Williamson Dec 22 '10 at 18:53

Your Answer

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

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