aix script search for different files send email

Hi. I'm new to this,

I need to create a script that searches for 5 different types of files, sends results to a text file and if any of the files are found, to send an email to our unit.

The files all fall under a certain directory, but could be anywhere in a sub-directory past that point.

Right now I just have a find command listed separately looking for each file, as each find command is using the "*" somewhere within it

I don't know how to search all of these, if any are found to send an email. I understand how to get an email from one find, but not 5.

Four of the files being searched are using the name, only one is searching for the extension.  I don't know if that makes a difference in how this is to be written, but as I said, I'm new to this, and its taken me 3 days to get this far.

Once this script is written, we will be putting it in our cron.

Any and all assistance with this would be greatly appreciated! I'm on an AIX box, but I'm able to script in bash.
Q_BusterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
It would have been better if you had given some examples how your files are named.

Anyway, you can combine find's search criteria like this:

find /start/dir -type f \( -name file1 -o -name file2 -o -name file3 -o -name file4 -o -name "*.ext" \) -print > outputfile

Please note that the parentheses needed to group the search criteria must be escaped  using "\" to protect them from being interpreted by the shell.
No space is allowed between "\" and "(" or ")", but the spaces before and after "\(" resp. before and after "\)" are mandatory.

You can use wildcards with the different names (use quotes around the names then), but please be aware that there could be some overlaps - but even with overlaps the affected files will be shown only once (Example: "file*" and "file1*" in the search criteria).

find /start/dir -type f \( -name "file1*" -o -name "file2*" -o -name "file3*" -o -name "file4*" -o -name "*.ext" \) -print > outputfile


AIX has ksh by default. Are you indeed using bash?
0
Q_BusterAuthor Commented:
The files I've been asked to search for are "javacore.*", "Snap.*", "heapdump.*', "*.dmp" and "orbtrc.*"

The script is for WebSphere and WebSphere Portal, if we find any of these coredump, or heap dump files, we are to get an email notification.

I know AIX has ksh by default, but my supervisor said that as long as I specify bash in the script, it should run. Is this not the case?

Once I plug in your suggested find  /start/dir -type f \( -name "file1*" -o -name "file2*" -o -name "file3*" -o -name "file4*" -o -name "*.ext" \) -print > outputfile, am I just saying if outputfile exists, send email?

Again, appreciate your guidance in this.
0
woolmilkporcCommented:
>> if outputfile exists, send email? <<

The file will always get created, but if no results are found it will be empty.

You could test for a filesize greater than 0

if [[ -s outputfile ]] ; then
  : <send mail>
fi

As for the shell - if the first line in your script reads

#!/usr/bin/bash
or
#!/bin/bash

you're right, bash will be used (if it's installed, of course).

The actual format of the "#!" ("shebang") line   depends on where bash is located.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Q_BusterAuthor Commented:
I tried both

 find ~ -type f\( -name "javacore.*" -o -name "Snap.*" -o -name "heapdump.*" -o -name "*.dmp" -o -name "orbtrc.*" \) -print > output_file

and

 find ~ -type f\( -name "javacore.*" -o -name "Snap.*" -o -name "heapdump.*" -o -name "*.dmp" -o -name "orbtrc.*" \) -print | xargs ls -l >> output_file

and
 
 find ~ -type f\( -name "javacore.*" -o -name "Snap.*" -o -name "heapdump.*" -o -name "*.dmp" -o -name "orbtrc.*" \) -print | xargs ls -l >> ${output_file}

all are returning this when I run the script:

find: missing conjunction

This is the first time I've ever come across this message, and I'm not sure where the error lies. I've tried changing the path of where to start looking for the files, I keep getting that error. What does that mean?
0
woolmilkporcCommented:
Didn't I write above:

No space is allowed between "\" and "(" or ")", but the spaces before and after "\(" resp. before and after "\)" are mandatory.

So it's

find ~ -type f \( -name "javacore.*" -o -name "Snap.*" -o -name "heapdump.*" -o -name "*.dmp" -o -name "orbtrc.*" \) -print > output_file

Open in new window

i.e. a space between "-type f" and "\(".
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Q_BusterAuthor Commented:
You did say that, my copy and paste skills need as much help as my scripting. Sorry about that.

Thanks for your help.
0
Q_BusterAuthor Commented:
Got back to me in a super efficient manner, was patient with my newbie status. Very appreciated!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.