#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0

    Mailx problem in csh script


    Hi all,
    I need to sent email to multiple user.However , each time i sent out only 1 user receive that email.

    This is my list or multiple user address :
    Code:
    Email = " allan@gmail.com bruce@gmail.com steve@gmail.com "
    This 1 is my email coding:
    Code:
     mailx -s "${SUBJECT}" "${email}"
    Any 1 can help me solve it?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    From your other post (good idea to start a new thread on this, by the way!) we see that mailx is giving a hint about syntax:

    Code:
    usage: mailx [-FUm] [-s subject] [-r address] [-h number] address ...
           mailx -e
           mailx [-UHLiNn] [-u user]
           mailx -f [-UHLiNn] [filename]
    That is good! The ... after address means, in effect, "repeat as many times as needed". However, I suspect that based on other comments you have made the email addresses cannot be separated by spaces. The variable containing the email addresses does, unfortunately, have leading and trailing spaces so any simple conversion of space to other delimiter/separator will be made a touch more difficult by that. There are probably many ways that the required variable contents can be formed. First though, we'd need to know what IS required. Could you do a man mailx on your system and see what it has to say about the format/requirements of the address parameter?
    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. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    Hi,
    i already try run man mailx and the output same :
    Code:
    usage: mailx [-FUm] [-s subject] [-r address] [-h number] address ...
           mailx -e
           mailx [-UHLiNn] [-u user]
           mailx -f [-UHLiNn] [filename]
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    That's not too useful! Looks like it's play time ...!
    Try, manually (you may want to change the dummy.com part so that DNS lookups work):

    Code:
    mailx -s "A test" dummy1@dummy.com dummy2@dummy.com
    If that doesn't work, try:
    Code:
    mailx -s "A test" dummy1@dummy.com,dummy2@dummy.com
    Basically if we cannot get the man page to tell us what syntax we need to use, we will need to work it out ourselves.

    The mail addresses can be anything, really - just so long as the system will accept them; which probably means a valid domain name at least.

    You will need to 'mix and match' - quoting the strings, separately, togther, using different delimiters - comma and semi-colon are the usual/common ones I believe and see what will work.
    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. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    Hi,

    I try it ,but not error come out for both of that code. The output only sent to the 1st email address. While another is not received.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    That is just plain annoying ... *nix programs usually output errors if they get something they do not like. Maybe, just maybe, there is something in the system or mail logs?
    The other option, of course, is to go back to the loop over each email address on the variable and do an email per address.
    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
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    The other option, of course, is to go back to the loop over each email address on the variable and do an email per address.

    Wht u mean?
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    As I mentioned in the other thread, the otehr way woud be to put the sending of the email in a loop that sent out a mail to each address in the variable, instead of trying to send one mail to many people.
    To repeat, for ease of reference:
    Code:
    for emailaddr in `echo "$email"`
    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
    I have gone back and checked and I was working on a misapprehension about the variable $email - I thought it had the group name in first. Since it does not appear to do so I have tweaked the above code to stop it skipping over the first emai address.
    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
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    Hi,
    Sorry ,nothing wrong with ur early code..i do mistake in email address.

    However, I got i think still cannot find out:
    -d " " = for space
    ? = for tab
    Wht code for tab?
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    I've always had issues trying to get the tab character identified as a delimiter. It is ASCII 9: Ctrl-I, \t, 0x09, 11 (in octal), etc.

    According to this page you may be able to set the IFS environment variable (as suggested) to include tab as a delimiter.

    Note that I removed the cut command, as in this instance, where the variable only contains email addresses, we do not need to miss out or skip over any of the fields.
    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
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    Hi ,
    If my folder got this two thing:
    [QUOTE]
    group1_member
    group1_class
    group2_member
    group2_class
    [QUOTE]

    so this code :
    grep "^$class"
    The output is either group1 or group 2.However cannot different between group1_class or group1_member ?
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Ok, we may need to modify what we look for and how we return the information! From that data what what do you need? Do you want just the group name (the part to the left of the _) of each, do you want just the unique group names, do you want just the group names for members or classes?
    To make sure we all know what is going on it'd help to see a bit more of the code - basically the full line in use, what input is the grep working on, and from the input the type of return desired.
    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
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    Hi,

    Actually the $class output should be either group1 or group2.
    So,now the file2 content is like this:
    group1_sms 60123333333
    group1_email bruce@gmail.com
    group2_sms 60123338888
    group2_email hello@gmail.com

    So,when grep ^$class the class=group1 ,all group1_sms, group1_email, will be the output.

    But, i want it different between group1_sms and group1_email. So, how to edit this statement :
    Code:
    grep ^$class
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    It depends on how you want to handle things. On the basis that after the grep that we currently have the variable will contain a list of one or more entries, we can introduce (yet another!) loop and in that loop break down each entry into a group name part and a 'type' part, using awk with the -F_ parameter to use the underscore as a delimiter. So, within the loop let us assume we have group2_sms in the variable:

    Code:
    g_name=`echo "$variable" | awk -F_ '{print $1}'`
    g_type=`echo "$variable" | awk -F_ '{print $2}'`
    g_name would then contain group2 and g_type would contain sms. You could then have an if test (for sms and email) or a case statement if more than two types to vary the processing as needed.
    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

IMN logo majestic logo threadwatch logo seochat tools logo