Unix administration - Cron job doesn't work

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > July 2004 > Cron job doesn't work





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Cron job doesn't work
Karan

2004-07-24, 2:48 am

Hi,
Can somebody please advise why the 1st cron's job (at 8 AM) doesn't
work whereby the 2nd cron's job (at 9 AM) is OK?

However, when I executed the 1st statement under command line, it
worked and created a file called 'maillog-20040716' at the required
directory.

00 8 * * 5 cp -p /var/log/maillog /test/maillog-`date +%Y%m%d`
00 9 * * 5 cp -p /var/log/maillog /test/maillog


Regards,
William Park

2004-07-24, 2:48 am

Karan <ksc_lam02@yahoo.com> wrote:
> Hi,
> Can somebody please advise why the 1st cron's job (at 8 AM) doesn't
> work whereby the 2nd cron's job (at 9 AM) is OK?
>
> However, when I executed the 1st statement under command line, it
> worked and created a file called 'maillog-20040716' at the required
> directory.
>
> 00 8 * * 5 cp -p /var/log/maillog /test/maillog-`date +%Y%m%d`
> 00 9 * * 5 cp -p /var/log/maillog /test/maillog


/usr/bin/date

--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Toronto, Ontario, Canada
Lew Pitcher

2004-07-24, 2:48 am

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Karan wrote:
> Hi,
> Can somebody please advise why the 1st cron's job (at 8 AM) doesn't
> work whereby the 2nd cron's job (at 9 AM) is OK?
>
> However, when I executed the 1st statement under command line, it
> worked and created a file called 'maillog-20040716' at the required
> directory.
>
> 00 8 * * 5 cp -p /var/log/maillog /test/maillog-`date +%Y%m%d`
> 00 9 * * 5 cp -p /var/log/maillog /test/maillog


With the clues you've given, I'd have to say your problem relates to the PATH
environment variable.
1) the cron job that uses a PATH-qualified date binary fails, while the cron
job that uses only fully qualified names succeeds, and
2) when run from the commandline, the PATH-qualified command succeeds.

Change your 8AM job so that the date command is fully qualified, and try it
again.



- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBAe3pagVFX4UWr64RArzQAKC264mlGd4o
ah92GPNvJIa0puRVuACgxgTN
SmsHrkebe4b+/+k53uDOX3Y=
=bpjV
-----END PGP SIGNATURE-----
Bill Marcum

2004-07-28, 6:19 pm

On 23 Jul 2004 21:33:28 -0700, Karan
<ksc_lam02@yahoo.com> wrote:
> Hi,
> Can somebody please advise why the 1st cron's job (at 8 AM) doesn't
> work whereby the 2nd cron's job (at 9 AM) is OK?
>

% sign needs to be escaped in crontabs.


--
"Donna Hand of Ashburn, Va., waited five hours to see the casket and
spent about three minutes inside." --AP news story
Goran Larsson

2004-07-28, 6:19 pm

In article <H3mMc.18976$Fj.779783@news20.bellglobal.com>,
Lew Pitcher <lpitcher@sympatico.ca> wrote:

>
> With the clues you've given, I'd have to say your problem relates to the PATH
> environment variable.


Then how could cron find 'cp' but not 'date'?
The problem is with the '%' character.

$ man crontab
. . .
The sixth field of a line in a crontab file is a string that
is executed by the shell at the specified times. A percent
character in this field (unless escaped by \) is translated
to a NEWLINE character.

Only the first line (up to a `%' or end of line) of the com-
mand field is executed by the shell. Other lines are made
available to the command as standard input. Any line begin-
ning with a `#' is a comment and will be ignored. The file
should not contain blank lines.
. . .

The correct fix is to change `date +%Y%m%d` to `date +\%Y\%m\%d`.

--
Göran Larsson http://www.mitt-eget.com/
Chris F.A. Johnson

2004-07-28, 6:19 pm

On 2004-07-24, Karan wrote:
> Hi,
> Can somebody please advise why the 1st cron's job (at 8 AM) doesn't
> work whereby the 2nd cron's job (at 9 AM) is OK?
>
> However, when I executed the 1st statement under command line, it
> worked and created a file called 'maillog-20040716' at the required
> directory.
>
> 00 8 * * 5 cp -p /var/log/maillog /test/maillog-`date +%Y%m%d`
> 00 9 * * 5 cp -p /var/log/maillog /test/maillog


The percent sign (%) is special to cron and must be escaped.

man 5 crontab:

The ``sixth'' field (the rest of the line) specifies the command
to be run. The entire command portion of the line, up to a
newline or % character, will be executed by /bin/sh or by the
shell specified in the SHELL variable of the cronfile.
Percent-signs (%) in the command, unless escaped with backslash
(\), will be changed into newline characters, and all data after
the first % will be sent to the command as standard input.



The line should be:

00 8 * * 5 cp -p /var/log/maillog /test/maillog-`date +\%Y\%m\%d`

--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
William Park

2004-07-28, 6:19 pm

Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
> The percent sign (%) is special to cron and must be escaped.
>
> man 5 crontab:
>
> The ``sixth'' field (the rest of the line) specifies the command
> to be run. The entire command portion of the line, up to a
> newline or % character, will be executed by /bin/sh or by the
> shell specified in the SHELL variable of the cronfile.
> Percent-signs (%) in the command, unless escaped with backslash
> (\), will be changed into newline characters, and all data after
> the first % will be sent to the command as standard input.


Which OS or Distro is that? My Slackware Linux has something different.

--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Toronto, Ontario, Canada
Robert Melson

2004-07-28, 6:19 pm

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Saturday 24 July 2004 19:53, William Park wrote:

> Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>
> Which OS or Distro is that? My Slackware Linux has something
> different.
>
> --
> William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
> Toronto, Ontario, Canada

Can't speak for Chris, but a quick look at the crontab manpage on my
FreeBSD system shows almost identical wording. As well, I see the same
thing on a Solaris system to which I have access.

Bob

- --
Robert G. Melson Nothing is more terrible than
Rio Grande MicroSolutions ignorance in action.
El Paso, Texas Goethe
melsonr(at)earthlink(dot)net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFBAxj7GX60pjRVDrMRAueqAKCwzTfCOGqE
XeefKuxZ73tgVkFQXACg2JAL
NxrPGFj3zmMrbGpmyNicUA0=
=uK1d
-----END PGP SIGNATURE-----
Barry Margolin

2004-07-28, 6:19 pm

In article <2mgi41Fmhp93U1@uni-berlin.de>,
William Park <opengeometry@yahoo.ca> wrote:

> Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>
> Which OS or Distro is that? My Slackware Linux has something different.


That feature of the % in cron has been around since long before Linux.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Moe Trin

2004-07-28, 6:19 pm

In article <2mgi41Fmhp93U1@uni-berlin.de>, William Park wrote:
>Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
[vbcol=seagreen]
>Which OS or Distro is that? My Slackware Linux has something different.


Which cron daemon are you using? In Dead Rat Linux, and most versions
of Unix, it's Vixie-cron, and my man page is identical. The man page seems
to be quite old, as the bottom reads

AUTHOR
Paul Vixie <paul@vix.com>

24 January 1994

Looking at the package list from Slack90, I see

PACKAGE DESCRIPTION:
dcron: dcron (Dillon's Cron daemon)
dcron:
dcron: The cron daemon runs in the background and executes tasks on behalf of
dcron: users at the appropriate time. Many timed system tasks are started
dcron: with cron, such as the nightly indexing with updatedb.
dcron:
dcron: dcron was written entirely from scratch by Matthew Dillon.
dcron:

Can you say Apples and Oranges?

Old guy

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com