Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Variables in heredoc

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-22-2012   -   Original Discussion by woodson2
woodson2's Unix or Linux Image
woodson2 woodson2 is offline
Registered User
 
Join Date: Nov 2006
Last Activity: 18 May 2017, 2:30 PM EDT
Posts: 50
Thanks: 11
Thanked 0 Times in 0 Posts
Variables in heredoc

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?




Code:
#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

Sponsored Links
    #2  
Old Unix and Linux 05-22-2012   -   Original Discussion by woodson2
Corona688's Unix or Linux Image
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 13 June 2018, 6:37 PM EDT
Location: Saskatchewan
Posts: 22,696
Thanks: 1,183
Thanked 4,334 Times in 3,995 Posts
You can put redirection and pipes after a here-doc so, something like

Code:
tee filename <<EOF | sendmail -t
...
...
EOF

The Following User Says Thank You to Corona688 For This Useful Post:
woodson2 (05-22-2012)
Sponsored Links
    #3  
Old Unix and Linux 05-22-2012   -   Original Discussion by woodson2
woodson2's Unix or Linux Image
woodson2 woodson2 is offline
Registered User
 
Join Date: Nov 2006
Last Activity: 18 May 2017, 2:30 PM EDT
Posts: 50
Thanks: 11
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Corona688 View Post
You can put redirection and pipes after a here-doc so, something like

Code:
tee filename <<EOF | sendmail -t
...
...
EOF
Works perfectly. Thank you for the timely response.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
heredoc error check bheeshmaraja Shell Programming and Scripting 1 03-16-2011 12:34 PM
Problem in SFTP using heredoc bheeshmaraja Shell Programming and Scripting 13 03-16-2011 12:34 PM
HEREDOC with fdisk latenite Shell Programming and Scripting 3 09-27-2009 01:38 PM
How to convert byteArray variables to HexaString variables for Linux? ritesh_163 Programming 2 08-10-2008 11:55 PM
naming variables with variables Allasso Shell Programming and Scripting 2 06-27-2008 10:45 AM



All times are GMT -4. The time now is 05:32 AM.