Sponsored Content
Top Forums UNIX for Advanced & Expert Users Using Variable As Input For mailx Post 302207590 by GregWold on Friday 20th of June 2008 10:09:57 AM
Old 06-20-2008
Question Using Variable As Input For mailx

All,

I'm having difficulty using a variable as the body of an e-mail; I suspect it has to do w/quoting, but am not sure. Right now I have separate functions for sending information and for sending errors. I'd like to set a variable (BODY) to use as input to mailx so I can have a generic function to send mail from my script. The code in the send_event_request function works fine; I can use it to send mail, but can't seem to find a way to use the BODY variable. Also, I'm having problems getting the newlines to work in BODY. (Note: All other variables are set elsewhere in the script and work fine.)

Thanks in advance!

Code:
BODY="Please run Event $EVENT (${DC}CAHOLD) for the $UL_TIME Upload. Thanks!\n\n"
BODY=$BODY"Stats For $UL_FILE\n"
BODY=$BODY"----------------------\n"
BODY=$BODY"Records  : $LINE_COUNT\n\n"
BODY=$BODY"Started  : $START_TIME\n"
BODY=$BODY"Finished : $FINISH_TIME\n\n"
BODY=$BODY"*** NOTE ***\n"
BODY=$BODY"This is not a production script.\n"
BODY=$BODY"A production script would have been e-mailed to the ollowing users:\n"
BODY=$BODY"$CURRENT_USERS\n\n"
BODY=$BODY"-----------------------------------------------------------------------------------------\n"
BODY=$BODY"This e-mail was automatically generated by $SCRIPT_NAME on $HOST_NAME. Please do not reply."

send_event_request()
{
   echo "Sending e-mail request..."

   SUBJECT="TEST"
   TO="me@mydomain.com"

   `mailx -s "$SUBJECT" "$TO" <<-EOF #$BODY would go here
Please run Event $EVENT (${DC}CAHOLD) for the $UL_TIME Upload. Thanks!

Stats For $UL_FILE
----------------------
Records  : $LINE_COUNT

Started  : $START_TIME
Finished : $FINISH_TIME

*** NOTE ***
This is not a production script.

-----------------------------------------------------------------------------------------
This e-mail was automatically generated by $SCRIPT_NAME on $HOST_NAME. Please do not reply.`
   ~. 2>/dev/null
   EOF 2>/dev/null
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

mailx in cron using variable date

I am using a popular HOSTUMP script that dumps successfully to a log file named servername_a_`date +%m%d%y`.log I then want to kick off a second cron job that will email me that log. I am assuming it has to be something like 00 07 * * 2 mailx -s 'SERVERNAME Tape A Weekly Backup Log'... (1 Reply)
Discussion started by: seaquin
1 Replies

2. Shell Programming and Scripting

please help: how to redirect input into a variable

I'm trying to write a simple script program (C shell). I have a problem redirecting input into a variable. Say I have a variable called J, and there is file called result which contains just some number, say 5. Which command should I use to assign J value 5 from the file result. I tried the... (2 Replies)
Discussion started by: artur80
2 Replies

3. Shell Programming and Scripting

How to get variable input from a file

Hi guys, I want to input some variables from a file. I tried it with following script, for i in 1 2 3 4 do read varible1 varible2 < ddd.txt echo $varible1 $varible2 done ... (1 Reply)
Discussion started by: maheshsri
1 Replies

4. Shell Programming and Scripting

sending variable value via mailx

Hi all, I need to send a variable value in the script through mailx. Please find the script below but its not working. agents.sh: agents=`grep "Tot Agents " snapshot.dbm` if (( $? == 0 )); then mailx abc@gmail.com $agents fi (3 Replies)
Discussion started by: db2cap
3 Replies

5. Programming

How to check an input variable

Suppose we have a simple situation, like the following C++ instructions: int x; cout << "Insert x: "; cin >> x; while ( x-- < 0 ) ; Of course, if it is written something different from an integer, the while loop shall not end. So, how can we check if the input x is of the right type? (2 Replies)
Discussion started by: Luke Bonham
2 Replies

6. UNIX for Dummies Questions & Answers

Send email with attachment and body : mailx , waiting for input , signal Control D

Hi, I am trying to send email with attacment and body using "mailx" (cat body.txt; uuencode attach.txt) | mailx -s "Attachment" abc@xyz.com When i type this command, the shell is still waiting for me to enter something in standard input and press control D before it sends a mail and... (2 Replies)
Discussion started by: aliaszero
2 Replies

7. Shell Programming and Scripting

XML variable for input in same input file

Dear All , i stuck in one problem executing xml .. i have input xml as <COMMAND name="ARRANGEMENT.WRITE" timestamp="0" so="initial"> <SVLOBJECT> <LONG name="CSP_PMNT_ID" val="-1"/> <MONEY name="CSP_CEILING" amount="0.0" currency="AUD"/> ... (6 Replies)
Discussion started by: arvindng
6 Replies

8. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

9. Shell Programming and Scripting

How to get the input using variable?

Hi all, Using shell script i need to send this report to the user. The department number will be mentioned every time in the input file as an input. I am not sure how to write a script by taking the department number from the text file. select * from account where department in... (1 Reply)
Discussion started by: k.keerthi2005
1 Replies

10. UNIX for Beginners Questions & Answers

Variable not displaying in subject line of mailx email

Hi Newbie here with first post. I've got a shell script (ksh) whereby I run a SQL*Plus script and output the results to a file. I then check the output file in an if statement that looks like this: if ]; then export GAPNUM=`awk '{print $4}' $OUTFILE` if ] then mailx -s... (10 Replies)
Discussion started by: ltzwoman
10 Replies
XDG-EMAIL(1)															      XDG-EMAIL(1)

NAME
xdg-email - command line tool for sending mail using the user's preferred e-mail composer SYNOPSIS
xdg-email [--utf8] [--cc address] [--bcc address] [--subject text] [--body text] [--attach file] [mailto-uri address(es)] xdg-email {--help --manual --version} DESCRIPTION
xdg-email opens the user's preferred e-mail composer in order to send a mail to address(es) or mailto-uri. RFC2368 defines mailto: URIs. xdg-email limits support to, cc, subject and body fields in mailto-uri, all other fields are silently ignored. address(es) must follow the syntax of RFC822. Multiple addresses may be provided as separate arguments. All information provided on the command line is used to prefill corresponding fields in the user's e-mail composer. The user will have the opportunity to change any of this information before actually sending the e-mail. xdg-email is for use inside a desktop session only. It is not recommended to use xdg-email as root. See http://portland.freedesktop.org/EmailConfig for information on how the user can change the e-mail composer that is used. OPTIONS
--utf8 Indicates that all command line options that follow are in utf8. Without this option, command line options are expected to be encoded according to locale. If the locale already specifies utf8 this option has no effect. This option does not affect mailto URIs that are passed on the command line. --cc address Specify a recipient to be copied on the e-mail. --bcc address Specify a recipient to be blindly copied on the e-mail. --subject text Specify a subject for the e-mail. --body text Specify a body for the e-mail. Since the user will be able to make changes before actually sending the e-mail, this can be used to provide the user with a template for the e-mail. text may contain linebreaks. --attach file Specify an attachment for the e-mail. file must point to an existing file. Some e-mail applications require the file to remain present after xdg-email returns. --help Show command synopsis. --manual Show this manualpage. --version Show the xdg-utils version information. ENVIRONMENT VARIABLES
xdg-email honours the following environment variables: XDG_UTILS_DEBUG_LEVEL Setting this environment variable to a non-zero numerical value makes xdg-email do more verbose reporting on stderr. Setting a higher value increases the verbosity. EXIT CODES
An exit code of 0 indicates success while a non-zero exit code indicates failure. The following failure codes can be returned: 1 Error in command line syntax. 2 One of the files passed on the command line did not exist. 3 A required tool could not be found. 4 The action failed. 5 No permission to read one of the files passed on the command line. CONFIGURATION
Visit http://portland.freedesktop.org/EmailConfig for information how to configure xdg-email to use the email client of your choice. EXAMPLES
xdg-email 'Jeremy White <jwhite@example.com>' xdg-email --attach /tmp/logo.png --subject 'Logo contest' --body 'Attached you find the logo for the contest.' 'jwhite@example.com' xdg-email --subject 'Your password is about to expire' 'jwhite@example.com' 'bastian@example.com' 'whipple@example.com' AUTHOR
Kevin Krammer, Jeremy White. <kevin.krammer@gmx.at> <jwhite@codeweavers.com> xdg-utils 1.0 06/24/2007 XDG-EMAIL(1)
All times are GMT -4. The time now is 06:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy