Professional Web Applications Themes

Cron job doesn't work - Linux / Unix Administration

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,...

  1. #1

    Default Cron job doesn't work

    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,
    Karan Guest

  2. #2

    Default Re: Cron job doesn't work

    Karan <ksc_lam02> 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, <opengeometryyahoo.ca>
    Toronto, Ontario, Canada
    William Park Guest

  3. #3

    Default Re: Cron job doesn't work

    -----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 ([url]http://counter.li.org/[/url])
    Slackware - Because I know what I'm doing.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)
    Comment: Using GnuPG with Thunderbird - [url]http://enigmail.mozdev.org[/url]

    iD8DBQFBAe3pagVFX4UWr64RArzQAKC264mlGd4oah92GPNvJI a0puRVuACgxgTN
    SmsHrkebe4b+/+k53uDOX3Y=
    =bpjV
    -----END PGP SIGNATURE-----
    Lew Pitcher Guest

  4. #4

    Default Re: Cron job doesn't work

    On 23 Jul 2004 21:33:28 -0700, Karan
    <ksc_lam02> 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
    Bill Marcum Guest

  5. #5

    Default Re: Cron job doesn't work

    In article <H3mMc.18976$Fj.779783news20.bellglobal.com>,
    Lew Pitcher <lpitchersympatico.ca> wrote:
    > > 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.
    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 [url]http://www.mitt-eget.com/[/url]
    Goran Larsson Guest

  6. #6

    Default Re: Cron job doesn't work

    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 [url]http://cfaj.freeshell.org/shell[/url]
    ================================================== =================
    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
    Chris F.A. Johnson Guest

  7. #7

    Default Re: Cron job doesn't work

    Chris F.A. Johnson <cfajohnson> 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, <opengeometryyahoo.ca>
    Toronto, Ontario, Canada
    William Park Guest

  8. #8

    Default Re: Cron job doesn't work

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

    On Saturday 24 July 2004 19:53, William Park wrote:
    > Chris F.A. Johnson <cfajohnson> 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, <opengeometryyahoo.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)

    iD8DBQFBAxj7GX60pjRVDrMRAueqAKCwzTfCOGqEXeefKuxZ73 tgVkFQXACg2JAL
    NxrPGFj3zmMrbGpmyNicUA0=
    =uK1d
    -----END PGP SIGNATURE-----
    Robert Melson Guest

  9. #9

    Default Re: Cron job doesn't work

    In article <2mgi41Fmhp93U1uni-berlin.de>,
    William Park <opengeometryyahoo.ca> wrote:
    > Chris F.A. Johnson <cfajohnson> 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.
    That feature of the % in cron has been around since long before Linux.

    --
    Barry Margolin, [email]barmaralum.mit.edu[/email]
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Margolin Guest

  10. #10

    Default Re: Cron job doesn't work

    In article <2mgi41Fmhp93U1uni-berlin.de>, William Park wrote:
    >Chris F.A. Johnson <cfajohnson> wrote:
    >> The percent sign (%) is special to cron and must be escaped.
    >>
    >> man 5 crontab:
    >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 <paulvix.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

    Moe Trin Guest

Similar Threads

  1. $ftp->put doesn't work
    By Altan Tütek in forum PERL Modules
    Replies: 2
    Last Post: January 2nd, 05:18 AM
  2. Can anyone tell me why this doesn't work?
    By cre8ive1974 webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 2
    Last Post: August 8th, 05:53 PM
  3. Replies: 1
    Last Post: July 27th, 04:28 PM
  4. Help w/ SQL doesn't work
    By Rob in forum Microsoft SQL / MS SQL Server
    Replies: 3
    Last Post: July 4th, 12:36 AM
  5. why this doesn't work (tm)? :)
    By Matija Papec in forum PERL Miscellaneous
    Replies: 2
    Last Post: June 26th, 11:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139