Unix Shell - MAILX on an AIX server with arguments

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > September 2006 > MAILX on an AIX server with arguments





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author MAILX on an AIX server with arguments
DanceRat

2006-09-25, 7:34 pm

I'm having the darndest time with this but it seems like it would be a
simple thing I'm missing...

Basically, what I'm trying to do is have my cake and eat it too - if
there isn't a file for the body, (no mfile exists), then I want it to
just put whatever is typed out in argument #1 as the bodyfile - for
instance, I type in "this is a test" for the $1 argument and when it
sees that there isn't a file called "this is a test" it actually just
uses that string as the body.

Anyone have any ideas?



#!/bin/sh
# MAILX.SH - generic shell to perform mailx with attachments.
# requires module defined with 5 arguments
# 1 filename to use as e-mail body (needs fully qualified pathname).
# 2 filename to use as e-mail attachment (needs fully qualified
pathname).
# 3 subject line of e-mail.
# 4 space delimited e-mail "to" list
# 5 space delimited distribution lists (needs fully qualified
pathname).


mfile=$1
afile=$2
msubj='$3'
mto='$4'
catfiles=$5

command='mailx'

if [ "$afile" != "''" ]; then
cat "$mfile" > $afile.uu
uuencode $afile $afile >> $afile.uu
else
cat "Sorry, there were no attachments." > $afile.uu
fi

if [ "$msubj" != "''" ]; then
command=$command' -s '$msubj
else
command=$command' -s "E-Mail For You"'
fi

if [ "$mto" = "''" ]; then
command=$command' '`cat $catfiles`' < '$afile.uu
else
command=$command' '$mto' < '$afile.uu
echo $PWD
fi


err=$?
echo $command
eval $command
rm $afile.uu
err=$?
exit $err

Scott McMillan

2006-09-26, 1:22 pm

On 25 Sep 2006 16:54:22 -0700, "DanceRat" <kimberly.shaffer@gmail.com>
wrote:

>I'm having the darndest time with this but it seems like it would be a
>simple thing I'm missing...
>
>Basically, what I'm trying to do is have my cake and eat it too - if
>there isn't a file for the body, (no mfile exists), then I want it to
>just put whatever is typed out in argument #1 as the bodyfile - for
>instance, I type in "this is a test" for the $1 argument and when it
>sees that there isn't a file called "this is a test" it actually just
>uses that string as the body.
>
>Anyone have any ideas?
>
>
>
>#!/bin/sh
># MAILX.SH - generic shell to perform mailx with attachments.
># requires module defined with 5 arguments
># 1 filename to use as e-mail body (needs fully qualified pathname).
># 2 filename to use as e-mail attachment (needs fully qualified
>pathname).
># 3 subject line of e-mail.
># 4 space delimited e-mail "to" list
># 5 space delimited distribution lists (needs fully qualified
>pathname).
>
>
>mfile=$1
>afile=$2
>msubj='$3'
>mto='$4'
>catfiles=$5
>
>command='mailx'
>
>if [ "$afile" != "''" ]; then

[ -f "$mfile ] && {
> cat "$mfile" > $afile.uu

} || {
echo "$mfile" > $afile.uu
}
> uuencode $afile $afile >> $afile.uu
>else
> cat "Sorry, there were no attachments." > $afile.uu
>fi
>
>if [ "$msubj" != "''" ]; then
> command=$command' -s '$msubj
>else
> command=$command' -s "E-Mail For You"'
>fi
>
>if [ "$mto" = "''" ]; then
> command=$command' '`cat $catfiles`' < '$afile.uu
>else
> command=$command' '$mto' < '$afile.uu
>echo $PWD
>fi
>
>
>err=$?
>echo $command
>eval $command
>rm $afile.uu
>err=$?
>exit $err



I don't see that you reference mfile if there is no attachment, but
the same logic would apply there.


Scott McMillan
Scott McMillan

2006-09-26, 1:22 pm

On Tue, 26 Sep 2006 13:16:30 GMT, Scott McMillan
<smcmillan@twmi.rr.com> wrote:

>On 25 Sep 2006 16:54:22 -0700, "DanceRat" <kimberly.shaffer@gmail.com>
>wrote:
>
> [ -f "$mfile ] && {


should be

[ -f "$mfile" ] && {

> } || {
> echo "$mfile" > $afile.uu
> }
>
>
>I don't see that you reference mfile if there is no attachment, but
>the same logic would apply there.



Scott McMillan
DanceRat

2006-09-26, 7:27 pm

Thanks Scott, I was missing the logical thought that I don't need to
check for an attachment if I'm using either /or for my bodyfile
statement.

long week and it's only Tuesday.

me

Scott McMillan wrote:
> On Tue, 26 Sep 2006 13:16:30 GMT, Scott McMillan
> <smcmillan@twmi.rr.com> wrote:
>
>
> should be
>
> [ -f "$mfile" ] && {
>
>
>
> Scott McMillan


Bill Marcum

2006-09-27, 1:36 am

On 25 Sep 2006 16:54:22 -0700, DanceRat
<kimberly.shaffer@gmail.com> wrote:
> I'm having the darndest time with this but it seems like it would be a
> simple thing I'm missing...
>
> Basically, what I'm trying to do is have my cake and eat it too - if
> there isn't a file for the body, (no mfile exists), then I want it to
> just put whatever is typed out in argument #1 as the bodyfile - for
> instance, I type in "this is a test" for the $1 argument and when it
> sees that there isn't a file called "this is a test" it actually just
> uses that string as the body.
>
> Anyone have any ideas?
>

if [ -f "$mfile" ]; then
cat "$mfile" > $afile.uu
else
echo "$mfile" > $afile.uu
fi



--
It's there as a sop to former Ada programmers. :-)
-- Larry Wall regarding 10_000_000 in <11556@jpl-devvax.JPL.NASA.GOV>
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com