Email sending through a shell script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Email sending through a shell script
# 1  
Old 10-30-2007
Email sending through a shell script

Hi everyone,
I have a shell script that I use to send some emails with attachments. Based on the attachment file that is being sent, I choose the recipient.

My file_list.txt looks like this

CAJ.txt;sm@email.com
KXLD.txt;jc@email.com

I do a grep on this file to look for the file name and extract the second field and store it in another variable as below.

email_dest= grep $FILENAME file_list.txt|cut -d ";" -f 2;

When I echo this variable it gives me the correct email address.

However when I try to send the email using this variable using the syntax,

mailx -s $FILENAME $email_dest
or mailx -s $FILENAME ${email_dest}

I get the following error message-

The flags you gave are used only when sending mail.
Usage: mailx -eiIUdFntBNHvV~ -T FILE -u USER -h hops -r address
-s SUBJECT -f FILE users

When I replace the variable with the email address, it sends the emails correctly. I have a feeling there might be a line feed character somewhere that is causing an issue but not sure how I can get rid of it.

Can anyone provide inputs as to how I can work around this or any other solution that would be more efficient. Thanks!
# 2  
Old 11-11-2007
The error message implies you aren't supplying the email address at all.
Chuck a -x on the end of your #! path at the top of the script and consider adding an 'echo $email_dest' just before the call to mailx to see what it's doing.
# 3  
Old 11-12-2007
Quote:
Originally Posted by memonks
email_dest= grep $FILENAME file_list.txt|cut -d ";" -f 2;
i'd say it's this line. if you're trying to run a command to be passed to a variable, you need back ticks (aka grave accents):

Code:
email_dest=`grep $FILENAME file_list.txt|cut -d ";" -f 2;`

in bash, you can also use:

Code:
email_dest=$(grep $FILENAME file_list.txt|cut -d ";" -f 2;)

# 4  
Old 11-12-2007
Thanks Idle, it was the grave accent that was missing. I was sure it was something small that I was missing.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sending email in shell script

Can anyone help me out how to send the email without the word success while sending to the recipient. echo "success" | mailx -s "webshell instance has been started noiw" implementation@tkcl.com (8 Replies)
Discussion started by: ramkumar15
8 Replies

2. Shell Programming and Scripting

Using top command to email if process is exceeding 25% and sending an email alert if so

This is my first time writing a script and Im having some trouble, Im trying to use the top command to monitor processes and the amount of CPU usage they require, my aim is to get an email if a process takes over a certain percentage of CPU usage I tried grep Obviosly that hasnt worked, Any... (8 Replies)
Discussion started by: jay02
8 Replies

3. AIX

Sending script output as email

Hi i have a script which executes daily through cron. The output of the script is appended to a log file everyday It also emails me the output of the logfile as we have the mailx command in the script The below is my requirement : Normally When I get the email it sends the entire content... (3 Replies)
Discussion started by: newtoaixos
3 Replies

4. Shell Programming and Scripting

Sending email from shell script

Hi, I need to send email from a shell script. i echoed some information to a file and i am doing cat command in the email syntax thanks (2 Replies)
Discussion started by: rocky1954
2 Replies

5. Shell Programming and Scripting

Configure gmail in linux shell for sending email

Hello, i have a problem sending emails in the command line. I have introduced this command: sendEmail -f my.account@gmail.com -t myself@domain.tld \ -u this is the test tile -m “this is a test message” \ -s smtp.gmail.com \ -o tls=yes \ -xu usernameonly -xp mypasswd but then i received... (1 Reply)
Discussion started by: limadario
1 Replies

6. Shell Programming and Scripting

Shell script for sending automatic email to personal mail id

hi guys, I need a shell script to send mail automatically to my personal mail id like xxxx@hotmail.com but while experimenting with "mail" command I faced following problems. cat text1.txt | mail -s 'test mail' xxxx@hotmail.com command successfully executed but while checking for... (4 Replies)
Discussion started by: rrd1986
4 Replies

7. Shell Programming and Scripting

sending email from a ksh script

hi all, i have a ksh script which is meant to send an email with an attachment. i use the following command to send email /usr/bin/uuencode $logFn $logFn | /usr/bin/mail -s "restoration results" $EMAILTO; where '$logFn' is the name of the file including the full path e.g... (0 Replies)
Discussion started by: cesarNZ
0 Replies

8. Shell Programming and Scripting

Running a shell script in cron...email not sending - help??

I am pretty new to Unix shell scripting, but wondered if anyone could help (in layman's terms if possible!!) :) I have a shell script which ultimately sends an alert to an email address if part of a batch of programs fails. Here's the script that sends the email: Script: 6check.csh... (8 Replies)
Discussion started by: tjhorwood
8 Replies

9. Shell Programming and Scripting

Sending attachments using email through shell script

Hi all, I have written a shell script which sends emails with attachments to our clients. All our attachments are simple flat files (.txt format). The script is working fine and sending the attachments to the mail-ids except that, when i am sending the attachments to non-outlook users (Like... (6 Replies)
Discussion started by: symhonian
6 Replies

10. Shell Programming and Scripting

sending email from KSH unix script.

Hi Need guidance on including code to mail a couple of files atached with some subject and mail body !!.. Thanks in advance (3 Replies)
Discussion started by: rosh0623
3 Replies
Login or Register to Ask a Question

Featured Tech Videos