Cron job doesn't work
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > Cron job doesn't work




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Cron job doesn't work  
Karan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-24-04 07: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,





[ Post a follow-up to this message ]



    Re: Cron job doesn't work  
William Park


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-24-04 07: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





[ Post a follow-up to this message ]



    Re: Cron job doesn't work  
Lew Pitcher


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-24-04 07: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 PAT
H
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-----





[ Post a follow-up to this message ]



    Re: Cron job doesn't work  
Bill Marcum


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11: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





[ Post a follow-up to this message ]



    Re: Cron job doesn't work  
Goran Larsson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11: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 P
ATH
> 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/





[ Post a follow-up to this message ]



    Re: Cron job doesn't work  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11: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





[ Post a follow-up to this message ]



    Re: Cron job doesn't work  
William Park


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11: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





[ Post a follow-up to this message ]



    Re: Cron job doesn't work  
Robert Melson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11: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-----





[ Post a follow-up to this message ]



    Re: Cron job doesn't work  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11: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 ***





[ Post a follow-up to this message ]



    Re: Cron job doesn't work  
Moe Trin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11: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 o
f
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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:10 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register