check file exist and age
check file exist and age
How to check if file exist if the folder name is chnaging every day. The check also needs ssh to logon.(username and password)
2017-02-01
2017-02-02
2017-02-01
2017-02-02
I don't insult, I diagnose.
Re: check file exist and age
Take a look at the plugins available here which may have one that works for you - https://exchange.nagios.org/index.php?o ... k_file_age
You may need to add in your own scripting to represent what the current date is for the dynamic changing folder name.
You may need to add in your own scripting to represent what the current date is for the dynamic changing folder name.
Former Nagios Employee
Re: check file exist and age
Non of them has a ssh login.
im searching for something like this?
./check_file_age -D \\directory\folder -u username -p password -f \%date%\* -c FILEMAXTIME
-u USERNAME -p PASSWORD -f WORKGROUP -D SMBSHARE -f FILEPATH -c FILEMAXTIME
im searching for something like this?
./check_file_age -D \\directory\folder -u username -p password -f \%date%\* -c FILEMAXTIME
-u USERNAME -p PASSWORD -f WORKGROUP -D SMBSHARE -f FILEPATH -c FILEMAXTIME
I don't insult, I diagnose.
Re: check file exist and age
You would need to find one that you can run in conjunction with check_by_ssh if none of them have the support for it, or write your own.
Once you're using check_by_ssh then you'll be able to execute a script locally.
Once you're using check_by_ssh then you'll be able to execute a script locally.
Former Nagios Employee
Re: check file exist and age
i forgot to mention not locally. I forgot the -H
I don't insult, I diagnose.
Re: check file exist and age
Code: Select all
#!/bin/bash
function usage {
echo -en "$EMSG"
echo -e "Usage:\n">&2
echo -e "`basename $0` -u USERNAME -p PASSWORD -W WORKGROUP -s SMBSHARE -f FILEPATH -c FILEMAXTIME -w FILESIZEMIN [-d]\n">&2
exit 3
}
#Process command line parameters
OPTERR=1
while getopts ":u:p:W:s:f:c:w:d" FLAG;do
#echo "-$FLAG $OPTARG"
[[ $OPTARG == -* ]] && echo "Invalid option: -$OPTARG">&2 && usage;
case $FLAG in
u) USER=$OPTARG;;
p) PASS=$OPTARG;;
W) WORK=$OPTARG;;
s) SHER=$OPTARG;;
f) FILE=$OPTARG;;
c) FMXT=$OPTARG;;
w) FSZM=$OPTARG;;
d) DEBUG='true';;
:) echo "Option -$OPTARG requires an argument.">&2;usage;;
\?) echo "Invalid option: -$OPTARG">&2;usage;;
esac
done
#Ensure required parameters are present
EMSG="Y U No enter all data?!?\n"
[ "$*" ]&&[ "$USER" ]&&[ "$PASS" ]&&[ "$WORK" ]&&[ "$SHER" ]&&[ $FILE ]&&[ "$FMXT" ]&&[ $FSZM ]||usage
#Make a samba call
LISTING=`smbclient $SHER $PASS \
-U $USER -W $WORK 2> /dev/null<< _END_
dir $FILE
_END_`
TNOW=`date +%s`
CRIT="yes"
WARN="no"
NEWC=0
#Parse resluts
FILES=`echo -e "$LISTING" | awk '$0~/^ [^.]/&&$(NF-6)!="D"'`
FILEC=`echo "$FILES"|wc -l`
IFS=$'\n';for LINE in $FILES;do
FILE=`echo $LINE|awk '{print $1}'`
SIZE=`echo $LINE|awk '{print $(NF-5)}'`
TIME=$(date +%s -d "`echo $LINE|awk '{print $(NF-4),$(NF-3),$(NF-2),$(NF-1),$NF}'`")
TDIFs=$(($TNOW-$TIME))
TDIFm=$(($TDIFs/60))
[ -n "$DEBUG" ] && echo $FILE - ${SIZE} bytes, ${TDIFm} min >&2
[[ $TDIFm -lt $FMXT ]] && $((NEWC++)) && CRIT='no'
[[ $SIZE -lt $FSZM ]] && WARN='yes'
done
[ $CRIT = "yes" ] && echo "No files found newer than $FMXT minutes!" && exit 2
[ $WARN = "yes" ] && echo "Files are smaller then $FSZM bytes!" && exit 1
echo OK - Found $FILEC files above $FSZM bytes and $NEWC newer than $FMXT minutes.
Can anyone help me out. Im not that good in .sh scripts.
I don't insult, I diagnose.
Re: check file exist and age
This will help walk you through adding the date - https://www.cyberciti.biz/faq/unix-linu ... -filename/
As this is a third party plugin, we're not able to provide direct support from it. The above link should help you out, though.
As this is a third party plugin, we're not able to provide direct support from it. The above link should help you out, though.
Former Nagios Employee
Re: check file exist and age
Filesys::SmbClient
Is not working with centos 7
Is not working with centos 7
I don't insult, I diagnose.
Re: check file exist and age
You're probably just missing the package.
Try yum install samba-client
Try yum install samba-client
Former Nagios Employee
Re: check file exist and age
Just checking in since we have not heard from you in a while. Did @rkennedy's post clear things up or has the issue otherwise been resolved?
Former Nagios employee