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

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: $?"
  • Comment on Re^2: Passing the contents of a file in a "system" call to a .ksh script
  • Download Code

Replies are listed 'Best First'.
Re^3: Passing the contents of a file in a "system" call to a .ksh script
by kennethk (Abbot) on Jan 08, 2009 at 20:31 UTC

    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!
        A few months ago, I wrote a secret santa script that involved automated e-mailing to a list contained in an external file. You may find it useful: Re: Temporarily Obscuring a Lottery Draw. Happy hunting.
      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!