Sponsored Content
Top Forums Shell Programming and Scripting Mailx Recipient and Name Script Post 302357627 by slicker on Wednesday 30th of September 2009 10:42:29 AM
Old 09-30-2009
Quote:
Originally Posted by pravin27
Hi ,
Here u go..

test_emal.txt file contains ur name and mail details.

#!/bin/sh
while read line
do
name=`echo $line | awk '{print($1)}'`
email=`echo $line | awk '{print ($2)}'`
if [ -z "$email" ]
then
echo " Hey how are u ? email id - $name"
else
echo " Hey Mr $name how r u ? email id - $email"
fi
name=''
email=''
done < test_emal.txt

Thanks for the response.

Sometimes though the name is 1, 2 or 3 fields, a name could be:

George
or
Mr Read
or
Mr George Read

So I would need to change the IFS to tab or multiple space characters perhaps?

---------- Post updated at 09:42 AM ---------- Previous update was at 08:18 AM ----------

I tried:

name=`echo $line | awk 'BEGIN { FS = "\t" } ; {print($1)}'`

and

name=`echo $line | awk -F"\t" '{print($1)}'`


These work on the command line but not in the script.

Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unknown recipient when using metasend

Hi, We use metasend to send e-mail from our app. This works fine with most kinds of mail, for example plain text, HTML with images and mail with attachments. But we still have one problem: If the to-address is misspelled, then still everything seems to be fine. We don't get any message back... (4 Replies)
Discussion started by: sjohnsen
4 Replies

2. Shell Programming and Scripting

Creating a multi-recipient email script

Well, I'm fairly new to shell scripting, so please excuse my newbieness :) I was wondering if it was possible to create a shell script that retrieves a list of recipients in a list_file and sends a message out all at once? An example of a list file would look similar to this: $ cat... (2 Replies)
Discussion started by: TheSunTheSea
2 Replies

3. UNIX for Dummies Questions & Answers

sendmail recipient issue

I can send external emails from one of my unix boxes but can no longer send internal emails, i have used mailx -v to see what's going on and it seems there is a problem with the RCPT TO part of the log It seems to add name@nsmail1.mydmn.gov.uk When it should be just name@mydmn.gov.uk The... (1 Reply)
Discussion started by: supadid
1 Replies

4. UNIX for Dummies Questions & Answers

mailx recipient restriction

maybe a simple question, but i've looked around and not been able to find anything. is there a restriction on how many recipients can be used in a single mailx command? whether it's a numeric restriction or a size restriction (like 256k for the whole recipient parameter). thanks a lot. (6 Replies)
Discussion started by: chris32680
6 Replies

5. UNIX for Dummies Questions & Answers

Configure Recipient Restrictions in Postfix

Hi all We need to block our users sending emails to specific email addresses. At the moment, recipient restrictions is not enabled in our Postfix relay server so all messages submitted from our Exchange server are accepted and relayed. See entries in our main.cf file: ### Recipient... (0 Replies)
Discussion started by: wbdevilliers
0 Replies

6. Shell Programming and Scripting

Send email recipient based on filename

Hi All can someone help please create a bash script. Here's a scenario: 1. I have a directory where it's a destination for scanned documents. e.g. /dest/scan 2. The filename is in the form IDNumber_Category. e.g. 123456_notes.pdf 3. The first part of the script is to rename the... (1 Reply)
Discussion started by: aemestech
1 Replies

7. Shell Programming and Scripting

sendmail script throwing an error "No recipient addresses found in header"

Hi, I am using following code to send an e-mail with attachment and body. echo "To: user1@mail.com,user2@mail.com" > mail.tmp echo "Cc: user3@mail.com,user4@mail.com" >> mail.tmp echo "From: group@mail.com" >> mail.tmp echo "Subject: my report" >> mail.tmp echo "please see as attached"... (6 Replies)
Discussion started by: vivek_damodaran
6 Replies

8. Programming

Mailx recipient from mysql database

Dear All, Can I make Mailx to read recipient address from a mysql database? I already tried emailing with bash script: SUBJECT="TEST" export EMAIL_ADDRESS=`mysql -uroot -pabcde smsd -e "SELECT email FROM recipient"` mysql -uroot -pabcde smsd -e "SELECT ID, SenderName, Body FROM inbox" |... (2 Replies)
Discussion started by: jazzyzha
2 Replies

9. Shell Programming and Scripting

Mailx recipient from mysql database

Dear All, Can I make Mailx to read recipient address from a mysql database? I already tried emailing with bash script: SUBJECT="TEST" export EMAIL_ADDRESS=`mysql -uroot -pabcde smsd -e "SELECT email FROM recipient"` mysql -uroot -pabcde smsd -e "SELECT ID, SenderName, Body FROM inbox" |... (14 Replies)
Discussion started by: jazzyzha
14 Replies

10. UNIX for Dummies Questions & Answers

Emails sent from Linux server are rejected by recipient

Hello i have this longterm issue which im unable to solve, i think this is quite simple issue, i hope you may know the cause It is on CentOS Redhat server with qmail installed. # service qmail status # service qmail start Starting Qmail: # ps aux | grep mail qmails 1688 0.0 0.0 ... (1 Reply)
Discussion started by: postcd
1 Replies
STRSTR(3)								 1								 STRSTR(3)

strstr - Find the first occurrence of a string

SYNOPSIS
string strstr (string $haystack, mixed $needle, [bool $before_needle = false]) DESCRIPTION
Returns part of $haystack string starting from and including the first occurrence of $needle to the end of $haystack. Note This function is case-sensitive. For case-insensitive searches, use stristr(3). Note If you only want to determine if a particular $needle occurs within $haystack, use the faster and less memory intensive function strpos(3) instead. PARAMETERS
o $haystack - The input string. o $needle - If $needle is not a string, it is converted to an integer and applied as the ordinal value of a character. o $before_needle - If TRUE, strstr(3) returns the part of the $haystack before the first occurrence of the $needle (excluding the needle). RETURN VALUES
Returns the portion of string, or FALSE if $needle is not found. CHANGELOG
+--------+-----------------------------------------------+ |Version | | | | | | | Description | | | | +--------+-----------------------------------------------+ | 5.3.0 | | | | | | | Added the optional parameter $before_needle. | | | | | 4.3.0 | | | | | | | strstr(3) was made binary safe. | | | | +--------+-----------------------------------------------+ EXAMPLES
Example #1 strstr(3) example <?php $email = 'name@example.com'; $domain = strstr($email, '@'); echo $domain; // prints @example.com $user = strstr($email, '@', true); // As of PHP 5.3.0 echo $user; // prints name ?> SEE ALSO
stristr(3), strrchr(3), strpos(3), strpbrk(3), preg_match(3). PHP Documentation Group STRSTR(3)
All times are GMT -4. The time now is 11:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy