Link to home
Start Free TrialLog in
Avatar of bkreynolds48
bkreynolds48

asked on

unix mailx .html file

trying to mailx my .html file - get the following errors

###############################
# end of the report file
#
exit
EOF
#
filename=`find /home/userid/sql/awr -type f -name '*awr*.html*' -mtime -1 -print`
/usr/bin/uuencode  $filename |mailx -s  "daily awr"  userid@mymail.com

############
#output from report file
#
End of Report
</body></html>
+ + find /home/bkbelk/sql/awr -type f -name *awr*.html* -mtime -1 -print
./awr_rpt.ksh[44]: find:  not found.
filename=
+ mailx -s daily awr  userid@mymail.com
+ /usr/bin/uuencode
./awr_rpt.ksh[45]: mailx:  not found.
Usage:  uuencode [-m] [infile] remotefile

##################################

adding the "-m"
############
# end of the report file
#
exit
EOF
#

filename=`find /home/userid/sql/awr -type f -name '*awr*.html*' -mtime -1 -print`
/usr/bin/uuencode -m  $filename |/usr/bin/mailx -s  "daily awr"    userid@mymail.com

############
#output from report file
#
./awr_rpt.ksh[44]: find:  not found.
filename=
+ mailx -s daily awr  userid@mymail.com
+ /usr/bin/uuencode -m
./awr_rpt.ksh[45]: mailx:  not found.
Usage:  uuencode [-m] [infile] remotefile
Null message body; hope that's ok

###########
I get an email but no attachment
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

uuencode needs two parameters:

1) the name of the input file
2) the name to be given this file on the remote side by "uudecode" and quasi "name of attachment" .

The first name can be omitted if and only if there is input from stdin.

The optional "-m" means "MIME compatible encoding format".
Note: Not all recipients understand the MIME encoding.

The simplest form is this:

/usr/bin/uuencode  $filename $filename |/usr/bin/mailx -s  "daily awr"  userid@mymail.com

Moreover, there seems to be an issue with your PATH setting, because the "find" utility cannot be located by the shell. What is the PATH setting, and where does your "find" reside? Do you run the script via crontab?
Try "/usr/bin/find" instead of just "find"!
Avatar of bkreynolds48
bkreynolds48

ASKER

the find by itself works fine
###########
find /home/userid/sql/awr -type f -name '*awr*.html*' -mtime -1 -print
/home/userid/sql/awr/awr_rpt-ORADEV.06-16-15.html
###########

could the problem be the name of the file?

###########

+ + find /home/userid/sql/awr -type f -name *awr*.html* -mtime -1 -print
./awr_rpt.ksh[44]: find:  not found.
filename=
+ /usr/bin/mailx -s daily awr bkbelk@magellanhealth.com
+ /usr/bin/uuencode -m
Usage:  uuencode [-m] [infile] remotefile
Null message body; hope that's ok
"find" from command line works, that's right.

But it doesn't work from inside the script.

The filename to be searched (-name) must of course be enclosed in quotes if it contains globbing characters,
but that's what you did.
The name of the matching file doesn't matter, as long as it doesn't contain spaces or other stuff which might confuse the shell in the later processing, but that's not the case here.

Did you try "/usr/bin/find"?
Which is your OS?
Do you run the script from crontab?

It would be nice if you could post the whole script!
Or add "echo $PATH" on a line of its own just above "find .. ..." and post the result.
HERE is the script and the output with the echo
I see the path is wrong for the find so I tried putting a
cd /home/userid/sql/awr
so the path is correct now and the find works but
the email is not an attachment it is some kind of
garbage in the body of the email
######################################

########
#!/usr/bin/ksh
set -x
########
#
export ORACLE_BASE=/u01/app/oracle
export ORACLE_ADMIN=/u01/app/oracle/admin
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/11204
export PATH=$ORACLE_HOME/bin
#
export ORACLE_SID=$1
#
sqlplus -s '/as sysdba' << EOF
set echo off
set head off
set feed off

column name noprint new_value dbname;
select name from v\$database;
col today noprint new_value xdate
select to_char( sysdate, 'MM-DD-YY') today from dual;

spool /home/userid/sql/awr/awr_rpt-&dbname..&xdate..html

SELECT output
   FROM (SELECT MIN(snap_id) minid, MAX(snap_id) maxid
           FROM dba_hist_snapshot
          WHERE begin_interval_time >= TRUNC(SYSDATE) - 1 AND end_interval_time < TRUNC(SYSDATE)),
        TABLE(
            DBMS_WORKLOAD_REPOSITORY.awr_report_html(
                (SELECT dbid
                   FROM v\$database),
                (SELECT instance_number
                   FROM v\$instance),
                minid,
                maxid
            )
        )
/
spool off
exit
EOF
#
cd /home/userid/sql/awr
echo $PATH
filename=`/usr/bin/find /home/userid/sql/awr -type f -name '*awr*.html*' -mtime -1 -print`
/usr/bin/uuencode  -m  $filename $filename |/usr/bin/mailx -s  "daily awr"   userid@mydomain.com
#####################

output from the above
#####################

+ echo /u01/app/oracle/product/11.2.0/11204/bin
/u01/app/oracle/product/11.2.0/11204/bin
+ cd /home/userid/sql/awr
+ + /usr/bin/find /home/userid/sql/awr -type f -name *awr*.html* -mtime -1 -print
filename=/home/userid/sql/awr/awr_rpt-ORADEV.06-16-15.html
+ /usr/bin/mailx -s daily awr userid@mydomain.com
+ /usr/bin/uuencode -m /home/userid/sql/awr/awr_rpt-ORADEV.06-16-15.html /home/userid/sql/awr/awr_rpt-ORADEV.06-16-15.html

#############
email body text (partial)
#############

begin-base64 644 /home/userid/sql/awr/awr_rpt-ORADEV.06-16-15.html
CjxodG1sIGxhbmc9ImVuIj48aGVhZD48dGl0bGU+QVdSIFJlcG9ydCBmb3IgREI6IEFJSFJYUFJE
LCBJbnN0OiBhaWhyeHByZCwgU25hcHM6CiA1NzcwMS01NzcyMzwvdGl0bGU+ICAgICAgICAgICAg
OK.

The PATH statement near the top of your script is incomplete:

export PATH=$ORACLE_HOME/bin

should rather read:

export PATH=$ORACLE_HOME/bin:$PATH

What you see in the email body is not really "garbage". It's the base64 (MIME) encoded HTML file.

It seems that the email client at the receiving side does not know how to decode base64.
Please try "uuencode" without the "-m" flag, so the standard UU encoding format wil be used.

Let's see.
OK
updated the PATH and took out the -m

 - I get the email with no text in the body and no attachment
Did you see the filename in your trace as before, like
filename=/home/userid/sql/awr/awr_rpt-ORADEV.06-16-15.html ?

Did you see any error messages from find/uuencode/mailx ?

Please repeat the whole run, keeping the updated PATH but re-adding -m. Do you see the garbage?
I see the filename and the path in the trac
that worked
I got the attachment
but the name is

homeuseridawrawr_rpt-ORADEV06-16-15.html

did I do something wrong?
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
without the "-m"

this worked
/usr/bin/uuencode  $filename $(basename $filename) | /usr/bin/mailx -s  "daily awr"   userid@mydomain.com


the attachment comes as an html file and is very readable
thanks so much for your help
Excellent!