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
SimpleX(3pm)						User Contributed Perl Documentation					      SimpleX(3pm)

NAME
Net::IMAP::SimpleX - Addons for Net::IMAP::Simple SYNOPSIS
use strict; use warnings; use Net::IMAP::SimpleX; Net::IMAP::SimpleX uses Net::IMAP::Simple as a base so the object creation is the same as it is for the ancestor: my $imap = Net::IMAP::SimpleX->new('imap.example.com') || die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr "; $imap->select("INBOX"); Net::IMAP::SimpleX is a collection of handy methods that are not simple, require Parse::RecDescent, or are experimental. DESCRIPTION
This module adds some useful, yet not so simple, extensions on top of Net::IMAP::Simple. METHODS
new For details on the invocation, read Net::IMAP::Simple. body_summary Typical invocations will take this overall shape. # get an object representation of the message body my $summary = $imap->body_summary($message_number); # multipart message if ($summary->has_parts) { for my $subpart ($summary->parts) { if ($subpart->has_parts) { ... } # examine the message part my @attr = map { $subpart->$_ } qw/content_type encoding encoded_size/; # fetch the raw message part my $subpart_body = $imap->get($message_number, $subpart->part_number); } } else { my $body = $summary->body; my @attr = map { $body->$_ } qw/content_type encoding encoded_size/ } This method returns a simple object that contains a representation of the body of a message. The object is built by a Parse::RecDescent parser using the output of an IMAP fetch body command. The parser uses the formal syntax as defined by RFC3501 http://tools.ietf.org/html/rfc3501#section-9 <http://tools.ietf.org/html/rfc3501#section-9>. my $body = $summary->body; my @attr = map { $body->$_ } qw/ content_description encoded_size charset content_type part_number format id encoding /; For multipart messages, the object contains sub-objects for each message part, accessible via the parts() method and inspected via the has_parts() method. The type method describes the type of multipart (such as mixed or alternative). The parts method returns a list of sub parts, which themselves may have subparts, and so on. An example of a multipart, alternative message with a text body and an html version of the body would looke something like: if ($summary->has_parts) { if ($summary->type eq 'alternative') { my ($html) = grep { $_->content_type eq 'text/html' } $summary->parts; } } A really complex, multipart message could look something like this: if ($summary->has_parts && $summary->type eq 'mixed') { for my $part ($summary->parts) { if ($part->has_parts && $part->type eq 'mixed') { ... } ... } } fetch The fetch command returns the various parts of messages that users request. It is fairly complicated (following RFC3501 using a grammar/parser), but there are some basic patterns that it follows. my $res =$imap->fetch('30:32' => 'UID BODY.PEEK[HEADER.FIELDS (DATE)] FLAGS') # $res = { # 30 => { # "BODY[HEADER.FIELDS (DATE)]" => "Date: Sun, 18 Jul 2010 20:54:48 -0400 ", # "FLAGS" => ["\Flagged", "\Seen"], # "UID" => 58890, # }, # 31 => { # "BODY[HEADER.FIELDS (DATE)]" => "Date: Wed, 21 Jul 2010 09:09:04 -0400 ", # "FLAGS" => ["\Seen"], # "UID" => 58891, # }, # 32 => { # "BODY[HEADER.FIELDS (DATE)]" => "Date: Sat, 24 Jul 2010 05:12:06 -0700 ", # "FLAGS" => ["\Seen"], # "UID" => 58892, # }, # } So-called "parenthized" lists will be returned as an array (see "FLAGS") but nearly everything else will come back as strings. This includes parenthized queries. Take "BODY.PEAK[HEADER.FIELDS (DATE FROM SUBJECT)]"), for example. The result would come back as the RFC822 header lines (as the above "Date: Sun, ..." has done). For more information about the different types of queries, see RFC3501. There's a surprising number of things that can be queried. uidfetch This is roughly the same thing as the "fetch()" method above, but the query runs on UIDs instead of sequence numbers. The keys of the $res are still the sequence numbers though. my $res =$imap->fetch('58890' => 'UID BODY.PEEK[HEADER.FIELDS (DATE)] FLAGS') # $res = { # 30 => { # "BODY[HEADER.FIELDS (DATE)]" => "Date: Sun, 18 Jul 2010 20:54:48 -0400 ", # "FLAGS" => ["\Flagged", "\Seen"], # "UID" => 58890, # }, # ... AUTHOR
INITIAL AUTHOR Jason Woodward "<woodwardj@jaos.org>" ADDITIONAL CONTRIBUTIONS Paul Miller "<jettero@cpan.org>" [fetch()] COPYRIGHT
Copyright (c) 2010 Jason Woodward All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. LICENSE
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. BUGS
https://rt.cpan.org/Dist/Display.html?Queue=Net-IMAP-Simple <https://rt.cpan.org/Dist/Display.html?Queue=Net-IMAP-Simple> SEE ALSO
perl, Net::IMAP::Simple, Parse::RecDescent perl v5.14.2 2012-02-11 SimpleX(3pm)
All times are GMT -4. The time now is 09:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy