Page 1 of 1
AIX Check for New Files
Posted: Fri Mar 07, 2014 5:39 pm
by costanza2k1
Hi all,
I want to be able to see if there are any news files within a specific directory:
Directory:
/usr/IBM/WebSphere7.0/profiles/AppSrv01
Files:
If any new files show up in this directory named: *.txt, *.phd, *.trc
If there are any files with those extensions then I need a critical alert...any suggestions?
Re: AIX Check for New Files
Posted: Mon Mar 10, 2014 9:11 am
by tmcdonald
Now there's an important distinction to make: Do you want to alert crit if there are *new* files or *any* files with those extensions?
I ask because the former will be a bit more complicated than the latter.
Re: AIX Check for New Files
Posted: Mon Mar 10, 2014 9:35 am
by costanza2k1
tmcdonald wrote:Now there's an important distinction to make: Do you want to alert crit if there are *new* files or *any* files with those extensions?
I ask because the former will be a bit more complicated than the latter.
The requirement is if there are any files with those extensions.
Re: AIX Check for New Files
Posted: Mon Mar 10, 2014 11:03 am
by sreinhardt
Here is a
very basic check for what you are looking for. This will check the path given as the first argument for any comma separated list of extensions(without spaces). Such that a directory listing of
Code: Select all
-rw------- 1 nagios users 303 Mar 7 13:30 checkjSpv6v
-rw------- 1 nagios nagios 257 Mar 4 14:58 checkpSs3D9
-rw-r--r-- 1 root root 0 Feb 28 10:05 FLAG
drwxr-xr-x 6 root nagcmd 4096 Nov 7 16:35 Getopt-Long-2.38
drwxr-xr-x 9 root root 4096 Mar 4 15:02 nagiosxi
drwxr-xr-x 9 root root 4096 Oct 21 17:53 vmware-vsphere-cli-distrib
-rw-r--r-- 1 root root 38424689 Feb 11 14:11 xi-latest.tar.gz
Will return the following results:
Code: Select all
./check_files.sh ./ check
Critical - Found files with bad extensions.
./check_files.sh ./ abcd
OK - No files with bad extensions found.
./check_files.sh ./ abcd,check
Critical - Found files with bad extensions.
Plugin:
Code: Select all
#!/bin/bash
# check if certain types of files exist.
IFS="," # set separator for for loop
for ext in $2; do # check for each file extension in given arg
if [[ $(ls -lva $1 | grep -i $ext | wc -l) -gt 0 ]]; then # if any files are found with this ext, will be greater than 0, exists on first find.
echo Critical - Found files with bad extensions.
exit 2
fi
done
# if we get here, there have been no files found with those names.
echo OK - No files with bad extensions found.
exit 0
Re: AIX Check for New Files
Posted: Mon Mar 10, 2014 2:17 pm
by costanza2k1
Thank you! I'll try this now.
Re: AIX Check for New Files
Posted: Mon Mar 10, 2014 2:26 pm
by sreinhardt
You're welcome, let us know how it works for you. You are of course welcome to modify as needed, like if you would like to know how many of a given file type there were... However I don't want to get too deep into custom development.