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?
AIX Check for New Files
Re: AIX Check for New Files
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.
I ask because the former will be a bit more complicated than the latter.
Former Nagios employee
- costanza2k1
- Posts: 197
- Joined: Fri Aug 09, 2013 12:19 pm
Re: AIX Check for New Files
The requirement is if there are any files with those extensions.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.
-
sreinhardt
- -fno-stack-protector
- Posts: 4366
- Joined: Mon Nov 19, 2012 12:10 pm
Re: AIX Check for New Files
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
Will return the following results:
Plugin:
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
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.
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 0Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
- costanza2k1
- Posts: 197
- Joined: Fri Aug 09, 2013 12:19 pm
Re: AIX Check for New Files
Thank you! I'll try this now.
-
sreinhardt
- -fno-stack-protector
- Posts: 4366
- Joined: Mon Nov 19, 2012 12:10 pm
Re: AIX Check for New Files
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.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.