Test Crontab

Posted on 2012-09-06
Last Modified: 2012-09-10
Is there a way i can test my crontab to see if it is working?
Question by:deklinm
    LVL 68

    Assisted Solution

    No, not really.

    "crontab" performs a syntax check on its own, so the general format as well as the time/date specifications should be formally correct.

    Cron just starts (or tries to start) the specified programs/scripts using sh, according to these time/date specifications.
    It doesn't care whether these executables exist or do the right things.

    Anything sent to stdout/stderr by these programs will be mailed to the owner of the crontab,
    and cron also writes a log of its activities. The location of the log is OS dependent, mostly /var/log/cron or the like.
    LVL 30

    Assisted Solution

    by:Kerem ERSOY
    You can create a cron task and see if it works.

    For this run cron -e for the user who you want to run the task. and just do run tish command

    * * * * * echo "This is a cron task"

    Open in new window

    This works for most distros but to get it work in RedHAT and derivatives such as CentOS etc. you'd rather edit /etc/crontab and add this line there instead


    save exit and wait for the email to the relaed user.
    LVL 19

    Accepted Solution

    most errors with scripts running under crontab are related around paths, for example, typing ifconfig on the command line will work because the path to the ifconfig program is in your environment, in cron this is different and it's usually best to specify the full paths for each command, to check to see if it's running, you aschedule a job and look at the errors (usually mailed to the root user or the MAILTO user in the crontab file).
    LVL 11

    Assisted Solution

    Or if you want to test without email, you could add something like this to your crontab:
        * * * * * date >/tmp/date.out 2>&1
    Then wait a minute and check to see if there's a timestamp (or error) in that file.  Remember to delete the above from the crontab when you've finished the test.

    I haven't seen a system where KeremE's suggestion of:
        cron -e
    edits the crontab.  From my experience it is usually:
        crontab -e
    LVL 6

    Assisted Solution

    The logs for cron should be in /var/log/cron

    You can run grep -i "whatyouarelookingfor" /var/log/cron

    So say you have a true multi-user system where all the users have their own /home/user directory. You can run grep -i user /var/log cron

    If that is not feasible, you can run grep -i "nameofscriptfile" /var/log/cron - i.e. grep -i myfile.php /var/log/cron

    9x out of 10, the issue is not cron not running the job but the script failing. This can be because of additional flags needed for the binary that processes the script, or having to call that binary explicitly. Or just the fact that the script is coded improperly.

    php -q /home/user/myphpscript.php
    /usr/local/bin/php -q /home/user/myphpscript.php
    /usr/local/bin/php /home/user/myphpscript.php

    perl /home/user/


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now