Solved

unix mail oracle awr html report

Posted on 2014-04-29
30
809 Views
Last Modified: 2014-04-30
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
0
Comment
Question by:bkreynolds48
  • 11
  • 9
  • 9
  • +1
30 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40030492
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
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 40030553
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
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40030571
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.
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40030612
--->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
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40030619
>>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.
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40030634
-->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
0
 
LVL 34

Expert Comment

by:johnsone
ID: 40030670
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.
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40030731
-->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
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40030819
>>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.
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40031309
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.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40031874
>>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.
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40031936
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..
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40031947
>>uuencode $filename $filename)| ...

That doesn't look quite right to me.
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 40032007
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
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40032035
can you please post the whole code.. what you have actually tried..
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Author Comment

by:bkreynolds48
ID: 40032038
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
0
 
LVL 16

Accepted Solution

by:
Wasim Akram Shaik earned 500 total points
ID: 40032053
can you try this and post the output incase of any errors.. you can run this in terminal and later on keep this in a sh file to automate ..

rep_name=`find -type f -name '*awr*.html*' -mtime 1 -print`
uuencode $rep_name $rep_name| /usr/bin/mailx -s "daily awr report" me@work.com
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40032084
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
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 40032158
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
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40032189
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.
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 40032196
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
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40032203
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.
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40032416
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?
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 40032429
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
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40032442
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
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 40032483
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
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40032622
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
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 40032661
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?
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40032667
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
0
 
LVL 1

Author Closing Comment

by:bkreynolds48
ID: 40032681
Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now