Hi all, this is an old story, but it's still sometimes surprising:

The task

What i did

I wrote some perl....

disaster.pl --foo bar

...and a shell wrapper for cron:

#!/bin/bash /usr/local/bin/disaster.pl --foo bar > /dev/null 2>&1

The scenario

I've got a test machine and a production machine which are totally identical.

It is impossible to test on prod.

OS is SLES11.

The observation

Running the perl script as well as the shell wrapper via commandline or cron on test leads to the expected results.

The UID on test is root.

On prod the UID is another, let's say karl - for some reason.

On prod the cron job (shell wrapper) gets executed and cron writes this to syslog but the perl script doesn't write to syslog and doesn't mail.

But when i change the shell wrapper on prod to...

/usr/bin/perl /usr/local/bin/disaster.pl --foo bar  > /dev/null 2>&1

...it works.

The question

But why - what do i miss?

N.B.: Perl code, shell wrapper and crontab are OK, that's why i didn't post more details.

Update:

I tried all the given hints (most of them i did before posting) but i couldn't figure out the reason for this issue.

But fortunately i had solution: adding /usr/bin/perl in the shell wrapper did the job, although /usr/bin is already in the path when cron runs the script under my uid.

Thanks to all that helped.

Thanks for any hint and Best regards, Karl


In reply to The "Perl script on command line works but as cronjob it fails" story revisited by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.