Q_Buster
asked on
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.
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.
ASKER
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.
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.
>> 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.
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.
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You did say that, my copy and paste skills need as much help as my scripting. Sorry about that.
Thanks for your help.
Thanks for your help.
ASKER
Got back to me in a super efficient manner, was patient with my newbie status. Very appreciated!
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?