Page 3 of 3 First 123
  • Jump to page:
    #31
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    hi
    Code:
    email=`grep "^$3" $folder/config_2.txt | cut -d " " -f 2-`
    For this 1 the output for email is
    Code:
    allan@gmail.com Bruce@gmail.com
    But it cannot sent out to that address,since both of the email come out at 1 time.
    Since my code for sent to user email address is like this :
    Code:
     echo "$dir : $filecount" | mailx -s "${SUBJECT}" "${email}"
    Mean i need sent to allan@gmail.com. Then also sent the same email to bruce@gmail.com
  2. #32
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Ok, all that means is now that we have all the emails nicely snuggled up together we can, at the time of writing the email, loop over them and send out a mail to each in turn.
    If you post up the current version of your script I can make a better suggestion.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #33
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    Hi
    Ya ,this code is functionally like i want:
    Code:
    email=`grep "^$3" $folder/config_2.txt | cut -d " " -f 2-`
    But when i want sent out the output to each email user , it only sent to the 1 user. Other email user cannot detect in my script.
    This is my email sent out code :
    Code:
     if ( $filecount <= $limit ) then
                    echo "$dir : $filecount" | mailx -s "${SUBJECT}" ${email}
            else
                    echo "$dir : $filecount is over the limit $limit " | mailx -s "${SUBJECT}" "${email}"
            endif
    Mean in email..it need sent to allan@gmail.com and steve@gmail.com. But the system only sent out to allan@gmail.com
  6. #34
  7. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Ok, I understand and I think we have enough of the code to deal with this. There are, in fact, at least two ways of doing this. One way would be to send the same mail to each person in the $email variable - I am guessing that mailx permits multiple addressees in some way. The other way would be to surround that if statement in a loop which iterates over each email address in the variable and thus sends the mail to one person at a time.

    One 'usual' way of one mail to may people is to bcc them all, that way no-one sees anyone elses email address. mailx sends bcc mails using -b (followed by comma-delimited email addresses).

    So, we could change the mailx commands to be:

    Code:
    mailx -s "${SUBJECT}" -b ${bccemail}
    where we populate the new variable with the correct value first!
    To do that we just need to get all the 'fields' in the existing $email variable, 'squeeze' out any multiple space characters and then convert any single spaces left to be a comma:
    Code:
    bccemail=`echo "$email" | cut -d " " -f 2- | tr -s " "| tr " " ","`
    That pre-supposes that you can just send to bcc recipients. If not you'd either need to use bcc as above, but add in a 'dummy' email of some sort.

    The other method would be to use a loop of some form to parse the $email variable and pretty much keep the existing code - you'd just need to make a name change to the variables:
    Code:
    for emailaddr in `echo "$email" | cut -d " " -f 2-`
    do
      if ( $filecount <= $limit ) then
        echo "$dir : $filecount" | mailx -s "${SUBJECT}" ${emailaddr}
      else
        echo "$dir : $filecount is over the limit $limit " | mailx -s "${SUBJECT}" "${emailaddr}"
      endif
    done
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #35
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    Hi ,
    when i run that script this error come out:
    Code:
    mailx: illegal option -- b
    usage: mailx [-FUm] [-s subject] [-r address] [-h number] address ...
           mailx -e
           mailx [-UHLiNn] [-u user]
           mailx -f [-UHLiNn] [filename]
    Wht it mean?
  10. #36
  11. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    It means that the man page I looked at would be for a different version of mailx than the one you have!
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
Page 3 of 3 First 123
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo