Link to home
Start Free TrialLog in
Avatar of bkreynolds48
bkreynolds48

asked on

unix mail oracle awr html report

I have a cron job scheduled to create awr html reports every day
how do I automate mailing them to my pc account

the reports are named ending in .html.(a random generated number)

I need to find the latest one and /usr/bin/mailx the report to myself

I tried
find -type f -name '*awr*.html*' -mtime 1 -print |/usr/bin/mailx -s "daily awr report" me@work.com

but that just sent me the name of the file
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

My UNIX is very old and rusty and there are likely easier ways but off the top of my head try:

find -type f -name '*awr*.html*' -mtime 1 -exec cat {}\; |/usr/bin/mailx -s "daily awr report" me@work.com
Avatar of bkreynolds48

ASKER

slightwv,

I get find: 0652-108 An expression term lacks a required parameter

the unix system is AIX 6.1- don't know if that makes a difference
Yeah, told you I was rusty.

Until someone else shows up, read the man page on your AIX system for the find command.

There should be an example with the -exec option.

Basically what your previous find command told the system to do is '-print' the name of the files it found and nothing else.  That is why you got the filename in the mail.

The '-exec' option says, take what you found and execute some command against it.  In my example:  cat it.
--->find -type f -name '*awr*.html*' -mtime 1 -print |/usr/bin/mailx -s "daily awr report" me@work.com

--->but that just sent me the name of the file

you would need uuencode command to send a mail attachment in unix

As you said, it gives you file name, so this should work

filename=find -type f -name '*awr*.html*' -mtime 1 -print

find -type f -name '*awr*.html*' -mtime 1 -print |uuencode filename /usr/bin/mailx -s "daily awr report" me@work.com
>>As you said, it gives you file name, so this should work

Again, I'm rusty but think there are some syntax issues in there.

>>you would need uuencode command to send a mail attachment in unix

Where was it mentioned that it was to be an attachment?

If the contents of the awr report are just to be the message body I don't see encoding as necessary.  I also think there are some mailx tweaks needed to add attachments.
-->Where was it mentioned that it was to be an attachment?

I need to find the latest one and /usr/bin/mailx the report to myself

If you read carefully.. its there in question..!!

EDIT:

Also I ran a sample test and found the code to be ok

[root@host-7-25 demo]# touch awr.html
[root@host-7-25 demo]# ls awr.html
awr.html

[root@host-7-25 demo]# filename=`find -type f -name '*awr*.html*' -mtime 0`
[root@host-7-25 demo]# echo $filename
./awr.html
[root@host-7-25 demo]#

Open in new window


so with uuencode, you can receive the file as an attachment
I know that I am going to get told that I am wrong, but this is the way I have done it.

The file is text, so there really isn't a need to encode it.  If you want to send it in the body of the message, you can simply do this:

cat `find -type f -name '*awr*.html*' -mtime 1 -print` |/usr/bin/mailx -s "daily awr report" me@work.com

Open in new window


Now, if you want to get fancy, you can send it as an attachment, but I wouldn't invoke mailx to do that.  Way too bulky.  Go to the lowest level and just send  your message.  Something like this should work:

rep_name=`find -type f -name '*awr*.html*' -mtime 1 -print`
(
 echo "To: me@work.com"
 echo "Subject: AWR report"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/html"
 echo "Content-Disposition: inline"
 cat $rep_name
 echo '---q1w2e3r4t5'
) | /usr/sbin/sendmail me@work.com

Open in new window


There are more fancy ways to do it using base64 coding and uuencode, but there isn't a need for that with purely text.

I did this mostly from memory, but it should be really close to what you are trying to do.  The only thing that may be missing is the file name on the attachment.
-->I know that I am going to get told that I am wrong

:) ., No way, if you have fulfilled the requirement, thats it.. its always depends on the result, only a few bother how you did it.!!!

I liked the option, personally i think AWR report would contain a lot of information, most people would prefer it as an html attachment or something, rather than in email body.. so i suggested to send it over mail using uuencode
>>filename=`find -type f -name '*awr*.html*' -mtime 0`

That isn't what you posted when I commented that there were some typos.  You missed the back quotes to actually execute the find and assign it to the variable.

What you originally posted wouldn't run.

Also:
Since you have the filename in $filename there is no need to re-execute the find for the uuencode and mailx.

>>I need to find the latest one and /usr/bin/mailx the report to myself
then
>>most people would prefer it as an html attachment or something, rather than in email body.. so i suggested to send it over mail using uuencode

That is all I was saying.  I didn't get 'attachment' from the original question.  You didn't mention it as an 'option' in http:#a40030612  it seemed as more of a mandatory correction.

If your email reader can interpret the HTML body, I prefer a message body over an attachment.  Then I can read an email and not have to open an attachment to launch some other program like a web browser to view it.

Granted the awr report might not scale well in a mail reader but...

All personal preference I guess.

>>its always depends on the result, only a few bother how you did it.!!!

I guess I'm among those few.  There is almost ALWAYS a blatantly wrong way to do something even if the end result is the same.

For example (over exaggerated by design):
Goal: Get 1 Million Dollars
option 1: save and invest wisely over many years
option 2: hold up an armored car

Both achieve the result.  Are both acceptable alternatives?

I suppose they might be once you weigh the risk/reward but I think one of them is clearly the wrong approach.
Steve, cool down... I showed the up the code as an approach,  I posted second comment as a sample run to show how it works.

-->That is all I was saying.  I didn't get 'attachment' from the original question.

Its an option with mail, so if one specifies or not, its worth posting. even author didn't specify he want it in mail body.

Well, My intention was about writing code, not stealing money. Lets not prolong this simple matter further.
>>I showed the up the code as an approach

All I pointed out was it had issues as posted.  You corrected one issue in your sample run but another one remains.
Ok :)
as you said still one more remains..here again a complete version

[root@host-7-25 demo]# touch awr.html
[root@host-7-25 demo]# ls awr.html
awr.html

[root@host-7-25 demo]# filename=`find -type f -name '*awr*.html*' -mtime 0`
[root@host-7-25 demo]# echo $filename
./awr.html
[root@host-7-25 demo]#uuencode $filename $filename)| /usr/bin/mailx -s "daily awr report" me@work.com

Open in new window



 unfortunately my server version doesn't have mail server configured, so unable to check whether it actually delivers mail or not.. but will work..
>>uuencode $filename $filename)| ...

That doesn't look quite right to me.
I DO want to send this as an attachment.
I tried uuencode and get this error

Usage: uuencode [-m] [infile] remotefile

not sure what that means
can you please post the whole code.. what you have actually tried..
I tried this:
rep_name=`find -type f -name '*awr*.html*' -mtime 1 -print`
(
 echo "To: me@work.com"
 echo "Subject: AWR report"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/html"
 echo "Content-Disposition: inline"
 cat $rep_name
 echo '---q1w2e3r4t5'
) | /usr/sbin/sendmail me@work.com

I tried putting this is a file
but get this error

Usage: find [-H | -L] Path-list [Expression-list]

so not sure what to do about that
I tried running this from the command line - that didn't work either
 
I want to automate this so I don't have to get on the system every day to find the files and email them to myself or go through them on the system

thanks
ASKER CERTIFIED SOLUTION
Avatar of Wasim Akram Shaik
Wasim Akram Shaik
Flag of India 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
Here is my suggestion:

find -type f -name '*awr*.html*' -mtime 1 -exec uuencode {} \; |/usr/bin/mailx -s "daily awr report" me@work.com

I used the following man page and the -exec example to correct what I believe was my error in my original post.  It also uses the suggested uuencode for an attachment.

http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.cmds/doc/aixcmds2/find.htm
I did this

find -type f -name '*awr*.html*' -mtime 1 -exec uuencode {} \; |/usr/bin/mailx -s "daily awr report" me@work.com

errors
find: 0652-018 An expression term lacks a required parameter
Null message body: hope that's ok

The email had nothing in it - no attachment
I was using the find from your original post.  Looks like it might be incorrect since there is no PATH from where to start the find.

See if this works:
find /some_starting_path -type f -name '*awr*.html*' -mtime 1 -exec uuencode {} \;

If it does, then we can add the '|' to mailx back in.
I did this

rep_name=`find -type f -name '*awr*.html*' -mtime 1 -print`
error
Usage: find [-H | -L] Path-list [Expression-list]

uuencode $rep_name $rep_name| /usr/bin/mailx -s "daily awr report" me@work.com
error
Usage: uuencode [-m] [infile] remotefile
Null message body: hope that's ok

email had nothing in it
Looks like I might be right.

Look at the usage message:  Usage: find [-H | -L] Path-list [Expression-list]

You are missing the PATH for the find.
I did this

rep_name=`find -type f -name '*awr*.html*' -mtime 1 -print`
error
Usage: find [-H | -L] Path-list [Expression-list]


i see nothing wrong in this syntax, this works perfectly fine for me,

also this did send me an email

uuencode $filename $filename)| /usr/bin/mailx -s "daily awr report" me@work.com

mine is AIX 6.1

which flavour and version of Unix are you using?
I did this
find /some_starting_path -type f -name '*awr*.html*' -mtime 1 -exec uuencode {} \;
this returns an error
find:0652-018 An expression term lacks a required parameter
Null message body: hope that's ok


I put the path in and did
find /some_starting_path -type f -name "*awr*.html*' -mtime 1 -print
and I get the file name

so not sure what else to try
any ideas?
I don't know much about uuencode - is there anyway to just send the file as an attachment with mailx or sendmail?

thanks
if you are able to get the file name like this, then try uuencode like this

file_name=find /some_starting_path -type f -name "*awr*.html*' -mtime 1 -print

uuencode -m $file_name $file_name| /usr/bin/mailx -s "daily awr report" me@work.com
tried this
file_name=find /some_starting_path -type f -name "*awr*.html*' -mtime 1 -print

echo $file_name
(this returns the correct file name)

uuencode -m $file_name $file_name| /usr/bin/mailx -s "daily awr report" me@work.com

get this error
Usage: uuencode [-m] [infile] remotefile
Null message body: hope that's ok


AIX 6.1
Well if you have the same version that i have, then this command should work in the same way as it had worked with me

the only difference i could see is the directory path like this, try placing the directory path

uuencode $UTL_DIR/$attc_file_name $attc_file_name)| mailx -s "Mailing File" -c cclist@gmail.com -r "Noreply@xxx.com" abc@gmail.com
I figured out the issue with uuencode
I had run the awr report twice today for testing and so $file_name had two files in it so that was why it didn't work

so can I put the find and the uuencode in my script that creates the report - at the end of the script to email the report attachment to myself just like it is here
 
file_name=find /some_starting_path -type f -name "*awr*.html*' -mtime 1 -print
uuencode -m $file_name $file_name| /usr/bin/mailx -s "daily awr report" me@work.com


or do I have to
export file_name in the script?
you don't have to explicitly use the export command..


you can place those commands in a file and schedule it via cron to get a email daily
Thanks