PDA

View Full Version : variables inside heredoc



woodson2
May 23rd, 2012, 01:38 AM
I currently use this message to send e-mails in a script but I would also like to save the output of this code to a file as well while preserving the variables. What's the easiest way to accomplish this?



#Sending mail notification
when=`/bin/date`
/usr/sbin/sendmail -t >2 <<-EOM
Subject:User access disabled.
From:testuser@test.com
To:$EMAIL
User $USERNAME has been disabled.


Regards,
$variable Support.
EOM

trent.josephsen
May 23rd, 2012, 02:43 AM
What do you mean by "while preserving the variables"?

Could the tee command be what you're looking for?

matt_symes
May 23rd, 2012, 01:40 PM
Hi

What about saving to the file and then sending that file ? (not as an attachment though)


#Sending mail notification
when=`/bin/date`
cat <<-EOM > filename
Subject:User access disabled.
From:testuser@test.com
To:$EMAIL
User $USERNAME has been disabled.


Regards,
$variable Support.
EOM

/usr/sbin/sendmail -t < filename

I have not tested this so i don't know if it works.

Kind regards