crontab help!

Posted on 2006-05-11
Last Modified: 2013-12-16
I have another newbie question, but this is starting to irk me.

I have crontab functioning properly.  3 of the commands are working beautifully in crontab.  I am a happy camper.

I have another set of commands that I run beautifully from the commands line.  I even write out the commands from the crontab -l in the command line and they work perfectly.  They don't work in crontab and I am forced to do the work myself.  I have checked everything in the commands and everything is done properly.  I am baffled.  The commands I am having problems with are unzip and mv.  I checked to make sure that I am launching the applications from the appropriate location and still nothing.  I have the following;

1 21 * * * /usr/bin/unzip /mnt/logs/somewhere/SOMELOGone`date +\%m-\%d-\%Y`*

Why doesn't this work?  It works perfectly in the command line.  Why not in crontab?  Am I missing something?

Question by:awakenings
    LVL 4

    Assisted Solution

    Try putting double quotes around: `date +\%m-\%d-\%Y`

    I think the shell is trying to interpret the single quotes.

    Been awhile, but this is what jumps out at me when looking at this.

    Author Comment


        I'll try that tomorrow.  I don't  think that is the answer as I have other entries that don't use double quotes.

    LVL 12

    Assisted Solution

    have you check the /var/log/message?? any error refer to this crontab job??

    also any error if you run the job manually??
    LVL 25

    Accepted Solution

    just out of curiousity what makes you think its not working.  agree with paul and check the logs, but I have to wonder if its unzipping the file, but not in the directory you want it.  if that is the case, change the cron line to this
    1 21 * * * cd <path to directory to unzip to> && /usr/bin/unzip /mnt/logs/somewhere/SOMELOGone`date +\%m-\%d-\%Y`*
    LVL 19

    Assisted Solution

    it it something to do with not locating the date command?

    On my system date is in /bin.... so try...

    1 21 * * * /usr/bin/unzip /mnt/logs/somewhere/SOMELOGone`/bin/date +\%m-\%d-\%Y`*

    Author Comment

    Paul, I'm still learning Linux.  How do you check the messages?

    Cyclops, I'll try your suggestion.  I thought it would go in the same directory.

    Jools, the date function works with other crontab messages without going to /bin.  I'm going to guess that is not the issue.

    LVL 25

    Assisted Solution

    /bin is usually one of the few entries in the PATH env var when running from cron so you shouldn't have a problem with that part
    LVL 15

    Assisted Solution

    be sure to check the log files for Cron, too - that's usually in:


    Author Comment

    Cyclops!  You wee right!  You get the most points!  I just tested and that was the issue.
    LVL 19

    Expert Comment

    Oops, just spotted the environment for /bin..... :-)

    The best way of checking the logs seems to be the email messages for root or whatever the root alias is set to.
    Looking at /var/log/cron doesn't seem to say that much!

    I've just been messing about on a FC4 system, at one stage it wasn't working, now it seems to be OK, I have the following as an example.

         * * * * * /usr/bin/unzip -o /tmp/myfile`date +\%m-\%d-\%Y`*

    The mail log shows this;

    Message 27:
    From root@test  Fri May 12 17:15:01 2006
    Date: Fri, 12 May 2006 17:15:01 +0100
    From: root@test (Cron Daemon)
    To: root@test
    Subject: Cron <root@test> /usr/bin/unzip -o /tmp/myfile`date +%m-%d-%Y`*
    X-Cron-Env: <SHELL=/bin/sh>
    X-Cron-Env: <HOME=/root>
    X-Cron-Env: <PATH=/usr/bin:/bin>
    X-Cron-Env: <LOGNAME=root>
    X-Cron-Env: <USER=root>

    Archive:  /tmp/
      inflating: tmp/allocatedb.tgz

    It could be that it is working on your system but it's going to the wrong directory as Cyclops pointed out.


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension ( This reminded me of questions tha…
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
    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.

    755 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

    22 Experts available now in Live!

    Get 1:1 Help Now