Shell script to send an email from the txt file


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to send an email from the txt file
# 1  
Shell script to send an email from the txt file

Hi Friends,

Could you guys help me out of this problem... I need to send an email to all the users and the email has to be picked from the text file.
text file contains the no. of records like:
Code:
giridhar
224285
847333
giridhar276@gmail.com
ramana
84849
33884
venkata.ramana@gmail.com
kishore
838393
484949
kishore.pulapa@gmail.com
venkat
434334
343433
venkateswararao@gmail.com

Every four lines make one record. For example consider the first record. I need to send a mail to giridhar276@gmail.com containing the his details "giridhar,224285,847333".
Now the details in the second record(next four lines) has to be sent to venkata.ramana@gmail.com

Like wise I need to send an email to other users alsooo......

Please help me.....

Last edited by pludi; 05-30-2011 at 10:44 AM..
# 2  
What have you tried so far, where are you stuck?
# 3  
Thanks alot for replying me .....

My requirement is to send only his details to his user id.. But I was unable to do that.......

Here, I was reading each line and storing every 4th line and sending all other details as well(but it's not my requirement).
I has to send only his particular details as I mentioned....

Code:
cat myfile.txt | while read line
do
count=`expr $count + 1`
if [ `expr $count % 4` != 0 ]
then
  mail -s "Please check your details" $line < mytext.txt
fi
done


Please help me.....

Moderator's Comments:
Mod Comment This is a forum run by volunteers. We aren't paid to help you, so please don't expect answers immediately. From the rules
Quote:
(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post or send a private message where your goal is to get an answer more quickly.

Last edited by pludi; 05-30-2011 at 11:58 AM..
# 4  
Code:
cat myfile.txt | while read line
do
count=`expr $count + 1`
if [ $count -eq 1 ]
then
    detail_1=$line
elif [ $count -eq 2 ]
then
    detail_2=$line
elif [ $count -eq 3 ]
then
    detail_3=$line
elif [ $count -eq 4 ]
then
    count=0
    echo $detail_1" "$detail_2" "$detail_4|mail -s "Please check your details" $line
fi
done

This will do your work, tough not so optimized.
# 5  
Code:
while read a
do
read b
read c
read email
echo $a $b $c |mail -s "your stuff" $email
done

# 6  
For the sake of the OP...

Don't forget the input file. Note that this method is more efficient than cat'ing the file and piping it to the while loop (you might get a useless use of cat award reconstruction of the Award text. :-) One less process needed. There are some other good tips on that page too.

Quote:
Originally Posted by jgt
Code:
while read a
do
read b
read c
read email
echo $a $b $c |mail -s "your stuff" $email
done < myfile.txt

# 7  
In a compact way...

cat <input_file> | paste -d, - - - - | sed 's,^,echo \",g;s,\,,\" | mail -s \"Record Details \" ,3' | sh
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #379
Difficulty: Medium
Solaris is UNIX V7, UNIX 03 and UNIX 98 compliant.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Send an email if "No such file or directory" in the shell script program log in EBS concur

Hi All, I have the below code(.sh) and need to send an email. #!/bin/bash cp /u02/xxc_incoming/TEST*.dat /u02/xxc_archive_incoming/AMER7764_ARPP_2/ cat /u02/xxc_incoming/TEST*.dat > /u02/xxc_incoming/XXC_TEST.dat rm /u02/xxc_incoming/TEST*.dat cd $XXC_TOP/bin sqlldr userid=apps/<pwd> ... (12 Replies)
Discussion started by: Mist123
12 Replies

2. Shell Programming and Scripting

how to send html email from shell script

This is my below script which is working fine as it send only plain text email. So My question is- How can I modify my below script to send this as an HTML formatted email? I want to show the text color of this expression `(echo "100*$TEST2/$TEST1" | bc -l)` as `RED` in an email and that can be... (3 Replies)
Discussion started by: raihan26
3 Replies

3. Shell Programming and Scripting

Help with shell script to send email once

Hi Guys, I have this script which will monitor oracle db process if up or down.And I want it to send email if it's down and the time it's back to online. However my script just keep on sending "Email Up" if the db is up or "Email Down" if the db is down.Is there any way to trap it so that it... (5 Replies)
Discussion started by: d3xt3r
5 Replies

4. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

5. Shell Programming and Scripting

How to send email through shell script

Hi All, I am new to the unix , i have to deliver one script very urgently I have to write a shell script where i have i want to send email to specific email id in this script i want FROM to be parameterized and stored in a variable TO to be parameterized and stored in a variable... (3 Replies)
Discussion started by: nileshbhawsar
3 Replies

6. Shell Programming and Scripting

How to send email once a day at certain time in unix shell script

hi, i have to send an email once a day at ceratin time say 22. i have tried with date commad, but not working.:( HOUROFTHEDAY=`date +'%H'` if ; then mailx -s "Info" emailid@org.com < $ProcessStatisticsFile fi Please help me... (5 Replies)
Discussion started by: sreelu
5 Replies

7. Shell Programming and Scripting

Shell script: If a file stays in a particular directory more than 30 min send an email

Hi , I am new to shell scripting. i have a requirement say i will receive a file in a directory say /xyz.if that file stays in that directory more than 30 min i need to get a mail to my outlook.this should run for every 20 min in crontab. can anyone help me? (8 Replies)
Discussion started by: muraliinfy04
8 Replies

8. Shell Programming and Scripting

make un shell script to send email

Hi, Someone Knows how to obtein a chain from a unix file, but not all the line, for exemple, for this file ,obtein only 902111111 and to keep the value, this value will be used to make a mailx. NF=ALL, SUBJ= FROM: SN=CD, SE=TOPCALL, NA=, N=902111111, N=TCLFI TO: SE=FAX, NA=, C1=... (0 Replies)
Discussion started by: peybol
0 Replies

9. Shell Programming and Scripting

need help in finding a string and to send an email using shell script

Hi All i am writing a shell script which will search for a string "expires". once the search string is found it has to give the email address as the output and send an email to the person This is basically to find the encrypetd keys which are loaded in the unix server Below are sample... (10 Replies)
Discussion started by: ranga27
10 Replies

10. Shell Programming and Scripting

How to write a shell script to send an email to an id

Hi all, I want to know how to send an email using shell script ..... I tried a command call mail but it did not work.. Please any one reply.. With example if you know thanks.. Madhu (4 Replies)
Discussion started by: madhumathikv
4 Replies

Featured Tech Videos