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

Have you considered sending the email from your perl script? Something like this:
my $log; ## Oops! Need this line, so $log is scoped beyond the {} my $LOGTIME = ... my @emails = qw(brother@elwood.com sister@elwood.com); my $LOGFILE = "/home/admin/logs/check_jvm/check_jvm_$LOGTIME.log"; open(LOG,"$LOGFILE") or die; { undef $/; $log = <LOG>; } close LOG; if (open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq")) { print SENDMAIL "From: PROD\@elwood.com\n" . "To: " . join(" ", @emails) . "\n" . "Subject: Web Server Issue\n" . "$log\n"; close(SENDMAIL); }
  • Comment on Re: Passing the contents of a file in a "system" call to a .ksh script
  • Download Code

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:20 UTC
    hbm, I couldn't figure it out. Here is some background. If we can send the email within the script, great! I have a list of users and email addresses kept in a file. We use a single file to make it simple to add/remove people on the list. If I start putting a separate list in every script, I will have a lot to maintain. The file uses the ":" character as a field separator, with the email address in field #5. The .ksh script is set up to use this properly with:
    for foo in `awk -F: '/ADMIN/ {print $5 }' $ADMINLIST`
    If I can set up Perl to read the config file in a similar fashion, awesome. Calling the external script seemed easier at the time.
      Elwood-- Here's one way:
      my @emails; my $ADMINLIST = '/path/to/admin.lst'; open(IN,"$ADMINLIST") or die("Can't open $ADMINLIST: $!"); while (<IN>){ if (my $addr = (split(/:/,$_))[4]) { push(@emails,$addr); } } close IN;

      That grabs the 5th element (numbered from zero) of each line; then you can print the list to the SENDMAIL pipe as I did earlier.