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.
Who is Participating?
woolmilkporcConnect With a Mentor Commented:
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 "\(".
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?
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.
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

>> 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>

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


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.
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


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

 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?
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.
Q_BusterAuthor Commented:
Got back to me in a super efficient manner, was patient with my newbie status. Very appreciated!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.