in reply to Passing the contents of a file in a "system" call to a .ksh script

Your post title and contents make me think perhaps you expect perl to pass the log file contents in place of the log file name. In that case, you need to specifically read the file contents and pass that - perlopentut goes through basic Perl file handling and includes examples that will do what you need. A basic read might look like:

use strict; use warnings; my $LOGFILE = 'file.log'; my @contents = (); open my $fh, "<$LOGFILE" or die "Failed to open $LOGFILE"; while (my $line = <$fh>) { push @contents, $line; } close $fh; print @contents;

If instead you expect to pass the file name, this would seem to be more of an issue with the shell script that with your Perl code. As you have written it, the system call should issue the following OS command:

/home/admin/bin/email.ksh /home/admin/logs/check_jvm/check_jvm_$LOGTIME.log Web Server Issue PROD /home/admin/logs/check_jvm/EmailAlert.log

where $LOGTIME should get interpolated assuming you assign it prior to your $LOGFILE assignment. Have you tried subbing your system call with print join ' ', @args to make sure you are passing what you think?

Update: Forgot to test my open. Fixed.

Replies are listed 'Best First'.
Re^2: Passing the contents of a file in a "system" call to a .ksh script
by BrotherElwood (Initiate) on Jan 08, 2009 at 20:12 UTC
    I may have missed something, it doesn't work. And yes, I am trying to send the contents of the log file to the script.
    open my $FH, "<$LOGFILE" or die "Failed to open $LOGFILE"; while ($LINE = <$FH>) { push @contents, $LINE; } close $FH; print LOG "$FORMATTEDTIME @contents \n"; my @args = ("/home/admin/bin/email.ksh", "@contents", "Web Server +Issue", "PROD", "/home/admin/logs/check_jvm/EmailAlert.log"); system(@args) == 0 or die "system @args failed: $?"

      The following is a cut/paste of your code with the addition of use strict;use warnings;, the addition of variable declaration, removing your LOG line and substituting "echo" for "/home/admin/bin/email.ksh".

      use strict; use warnings; my $LOGFILE = 'junk.txt'; open my $FH, "<$LOGFILE" or die "Failed to open $LOGFILE"; my @contents = (); while (my $LINE = <$FH>) { push @contents, $LINE; } close $FH; my @args = ("echo", "@contents", "Web Server Issue", "PROD", "/home/ad +min/logs/check_jvm/EmailAlert.log"); system(@args) == 0 or die "system @args failed: $?"

      It echos The contents of the file. Web Server Issue PROD /home/admin/logs/check_jvm/EmailAlert.log as expected. Are you sure you are invoking your shell script properly? Can you invoke it successfully from the command line? If it comes down to debugging a shell script or perl, I'd be inclined to suggest putting time in on hbm's suggestion.

        Kennethk, I have what you listed, but I pre-declared some of the variables at the start of the code. Something I am just used to. I may look into emailing within the script with a second email config file, just trying to stay away from doing so for obvious reasons. Thanks!
        Kennethk, I have what you listed, but I pre-declared some of the variables at the start of the code. Something I am just used to. I may look into emailing within the script with a second email config file, just trying to stay away from doing so for obvious reasons. Thanks!