Filestat as bash script

hi ymez,

I think we wrote the following for an AIX host where no python was available, feel free to change the name of the config file. No guarantee on it:

so far it only covers the file count feature, not oldest/newest/sizes etc but you can include more functions when parsing through each file in the while loop at the bottom of the script

example Config file: /etc/check_mk/sva_filestats.cfg

_SVA_FILESTAT_NAME[0]="OMPlus Queue Files"
_SVA_FILESTAT_PATH[0]="/usr/lpplus/queues"
_SVA_FILESTAT_NAME[1]="OMPlus Report Files"
_SVA_FILESTAT_PATH[1]="/usr/lpplus/reports"

plugin $MK_LIBDIR/plugins/sva_filestats

#!/opt/freeware/bin/bash
 
conf_file="sva_filestats.cfg"
echo "<<<filestats:sep(0)>>>"
  
if ! [ -r "${MK_CONFDIR}/${conf_file}" ] ; then
echo "Error - No config available... \"${MK_CONFDIR}/${conf_file}\""
else
source "${MK_CONFDIR}/${conf_file}"
fi
 
echo ${!_SVA_FILESTAT_NAME[@]} | tr ' ' '\n' | while read _ARRAY_INDEX ; do
  filecount=$(ls -1 ${_SVA_FILESTAT_PATH[${_ARRAY_INDEX}]} | wc -l)
  echo "[[[count_only ${_SVA_FILESTAT_NAME[${_ARRAY_INDEX}]}]]]"
  echo "{'count': $filecount, 'type': 'summary'}"
done

output is mk_filestat compatible, but doesn’t cover all the use cases mk_filestat has. Feel free to extend it but share if you can :wink:

1 Like