How to set mail subject using variable and ensure attachment is not included in email body
0
votes
1
answer
8745
views
I have the following shell script fragment.
var_name='ZZPCI'
for emailadd in
cat /tmp/email_list.tmp
do
subject_text="Subject with Var Name "$var_name
subj_text_novar="Subject without Var Name"
email_mssge="this is the message with variable name "$var_name
echo "$email_mssge"|mailx -a /tmp/my_report.txt -s "$subject_text" "$emailadd"
echo "$email_mssge"|mailx -a /tmp/my_report.txt -s "$subj_text_novar" "$emailadd"
done
What it does is
a. Sets the variable var_name
b. Reads through the list of email addresses stored in /tmp/email_list.tmp
c. Compiles and sends an email with /tmp/my_report.txt (plain text file) as an attachment
The script is intended to run on a number of different servers, so var_name will change with each server.
The mail command with $subj_text_novar, (does not include $var_name in the subject string), sends the email correctly .
However the mail command with $subject_text which does include $var_name places the contents of the attachment into the main body of the email.
As far as I can make out, it is the actual $-sign causing the problem because hardcoding the var_name value into the string is fine but I don't see why because surely var_name is just a concatenated string
So, how can I set the subject for mail so it includes $var_name and my text file is sent as an attachment?
I am running this on SuSE 11.3 but the solution ideally needs to work on AIX 6.1 and HP UX11.31 as well
Regards
Asked by Noj
(1 rep)
Jul 21, 2015, 03:28 PM
Last activity: Jun 14, 2025, 07:05 PM
Last activity: Jun 14, 2025, 07:05 PM