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

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.
  • 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 hbm (Hermit) on Jan 08, 2009 at 21:29 UTC
    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.