codeview
By:
codeview

Cannot get basic cron / cronjob to run (following the DO tutorial)

June 6, 2015 4.9k views
Getting Started Applications Linux Basics Linux Commands System Tools Ubuntu

My droplet is running Ubuntu 14.04 and I am using ServerPilot to manage it (although I don't think that matters for my question). I have followed the Digital Ocean tutorial for "how to use cron to automate tasks on a vps", here: https://www.digitalocean.com/community/tutorials/how-to-use-cron-to-automate-tasks-on-a-vps

But I get nothing happening...no cronjob runs, no email sent. Can anyone help me with what to do next - to troubleshoot or what else to try? This is currently what is in my crontab (copied from the tutorial, just replaced the example email with my email):

SHELL=/bin/bash
HOME=/
MAILTO=”example@digitalocean.com”
#This is a comment
* * * * * echo ‘Run this command every minute’

EDIT: When I enter crontab with crontab -e the file location is listed as "/tmp/crontab.0aXfre/crontab"...could that location be the problem?

4 comments
  • the quotes in your example that are around your email might need to be replaced with actual quotes..just re-type that entire line

  • I tried that before posting, actually. Still nothing. Is there any way to tell if the cron is running and just failing to complete and failing to send an email...I can't seem to find a log anywhere.

  • For safety reasons crontab -e opens in a tmp file, if it detects a problem it will not write to the actual crontab file. If there is no problem it will submit the new job, would comment out the MAILTO line and append the output to a log file then save the file and see what you get.

    • * * * * echo ‘Run this command every minute’ >> file.log Also I know it sounds silly but make sure cron is running
  • Thank you for the explanation of the tmp file. I have managed to get a basic echo to work now. This is my crontab:

    PATH=/usr/sbin:/usr/bin:/sbin:/bin
    SHELL=/bin/bash
    HOME=/
    MAILTO=me@mydomain.com
    * * * * * echo "Run this command every minute" >>/srv/users/serverpilot/apps/APPNAME/cron.log
    

    But no email is sent. I've also tried quotes around the email address (in some of my research I saw they were not present).

    *Am I correct to assume that I may need to have some form of mail configuration on my server that is not there my default? *I found some mentions of sSMTP?

    P.S. - yes, cron is running. It took me quite awhile to figure out how to check this: ps -ef | grep cron | grep -v grep and my output is: root 903 1 0 May23 ? 00:00:05 cron
    . This ServerFault post helped greatly: http://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it

2 Answers

This question was answered by @NotEnoughSquirrels:

For safety reasons crontab -e opens in a tmp file, if it detects a problem it will not write to the actual crontab file. If there is no problem it will submit the new job, would comment out the MAILTO line and append the output to a log file then save the file and see what you get.

  • * * * * echo ‘Run this command every minute’ >> file.log Also I know it sounds silly but make sure cron is running

View the original comment

My crontab doesn't seem to work

when i write "ps -ef | grep cron | grep -v grep", it doesn't show me any message
I tried to write the command "service cron start" and it says Cron is already working
I commented most of the commands and had a echo command but that also doesn't show anything.

  • WHen I run the command "sudo crontab -e", it throws following error:

    /var/spool/cron: No such file or directory
    /var/spool/cron: mkdir: No such file or directory

Have another answer? Share your knowledge.