cron output = 0 bytes

I have a cron job set to run a script everyday. If I run the script out side of cron it runs correctly. If cron runs the script is produces a 0 byte file and it puts the output in the / directory. The script is set to put the output in a specific directory. Any help would be appreciated.

check your 'script' for any type of the environment variables and make sure those are accessible from within cron.

I thought I read that cron needs to be able to see the path to the script or parameteres within the script. Is this set in /etc/default/cron.

Below is a copy of the script, (message_log.pl).

# more message_log.pl
#!/usr/local/bin/perl
#! /usr/bin/ksh
#MagicStore message log utility
( $sec, $min, $hour, $mday, $mon, $year,, ) = localtime();
$today = sprintf( "%04d%02d%02d", ( $year + 1900 ), ( $mon + 1 ), $mday );
print "Parsing through message log...........\n";
sleep 2;
system("mkdir log") if (! -d "./log");
InstallScript();

system("./dl.csh > /images_1/messages/dl.out");
system("./dl.awk /images_1/messages/dl.out > /images_1/messages/dl1.out");
#---------------Set the line below to what type of message you want to trap-----
---------
system("grep PAT_INCONSISTENT /images_1/messages/dl1.out>$today.message.log");
system("rm -f /images_1/messages/dl.out");
system("rm -f /images_1/messages/dl1.out");
print "Your file named $today.message.log is ready for viewing\n";

sub InstallScript
{

unlink("/images_1/messages/dl.csh");
open(CSH,">/images_1/messages/dl.csh");
print CSH "#!/bin/csh\n";
print CSH "source ~work/.cshrc\n";
print CSH "source /home/sn_root/bin/apc/apc_env.csh\n";
print CSH "/home/sn_root/bin/apc/apc << EOF\n";
print CSH "4\n11\n5\n1\nEOF\n";
close(CSH);
system("chmod a+rwx /images_1/messages/dl.csh");

unlink("/images_1/messages/dl.awk");
open(AWK,">/images_1/messages/dl.awk");
print AWK "#!/usr/bin/nawk -f\n";
print AWK 'BEGIN { FS="\n";';
print AWK 'RS = "" }';
print AWK "\n";
print AWK "{\n";
print AWK 'if(sub(/^ date *:/,"",$1)) {';
print AWK "\n";
print AWK 'sub(/^ message *:/,"",$2)';
print AWK "\n";
print AWK 'print $1,$2';
print AWK "\n";
print AWK "\n}\n}";
close(AWK);
system("chmod a+rwx /images_1/messages/dl.awk");

}

your perl is making some assumptions that might not hold true under cron - in terms of file paths:

system("mkdir log") if (! -d "./log");
system("./dl.csh > /images_1/messages/dl.out");
system("./dl.awk /images_1/messages/dl.out > /images_1/messages/dl1.out");
print CSH "source ~work/.cshrc\n";

Where and how do i modify the paths in cron. Or do i need to modify the script?

I'd modify the script to make it aware of:

  1. the directory where the script resides so that things like './dl.csh' can be resolved.
  2. the '~work/.cshrc'

Once cron references the script shouldn't the script already know where to go? Below is a listing from cron and it is already in the correct directory?

30 07 * * * /images_1/messages/message_log.pl

no, it doesn't as it's referencing relative paths which are not the same as they are under comman line shell.
Therefore, either make sure that your script does not make any refereneces to the relative paths.
OR
change your script so that it derives the paths from a constant location - for example the path to the script itself.

Awesome thanks for you help!

Now the only problem, which it is not that much of a problem is that it dumps the file into the root directory rather than /images_1/messages?