Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 555
  • Last Modified:

crontab help!

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?

Awakenings
0
awakenings
Asked:
awakenings
  • 3
  • 2
  • 2
  • +3
6 Solutions
 
jasonwilliams74Commented:
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.
0
 
awakeningsAuthor Commented:
Jason,

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

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

also any error if you run the job manually??
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
Cyclops3590Commented:
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`*
0
 
joolsCommented:
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`*
0
 
awakeningsAuthor Commented:
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.

Awakenings
0
 
Cyclops3590Commented:
/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
0
 
periwinkleCommented:
be sure to check the log files for Cron, too - that's usually in:

/var/log/cron
0
 
awakeningsAuthor Commented:
Cyclops!  You wee right!  You get the most points!  I just tested and that was the issue.
0
 
joolsCommented:
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/myfile05-12-2006.zip
  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.

J
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now