From ab955c9fa55ef873435219deadca28359d873b6c Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Mon, 13 Jan 2014 13:53:32 +0100 Subject: [PATCH] Changed the way variables for binaries are created --- nagios-bootstrap.sh | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/nagios-bootstrap.sh b/nagios-bootstrap.sh index 7cc79fd..27d2ee8 100755 --- a/nagios-bootstrap.sh +++ b/nagios-bootstrap.sh @@ -24,27 +24,29 @@ # Version 0.1 # Binaries -Nmap="/usr/bin/nmap" -Sed="/bin/sed" -Awk="/usr/bin/awk" -Printf="/usr/bin/printf" -Ls="/bin/ls" -Grep="/bin/grep" -Cut="/usr/bin/cut" -Tr="/usr/bin/tr" -Head="/usr/bin/head" +Which="/bin/which" +Binaries=(nmap sed awk printf ls grep cut tr head) # Variables Version="0.1" -Plugindir="dummy_checks" +Plugindir="dummy_checks/" -# Sanity check -for Bin in $Nmap $Sed $Awk $Printf; do - if [ ! -x $Bin ]; then - echo "Can't execute $Bin" + +# Sanity check binaries and create variables for them +Count=0 +for i in ${Binaries[@]}; do + $Which $i &> /dev/null + if [ $? -eq 0 ]; then + declare $(echo ${Binaries[$Count]^}=`${Which} $i`) + ((Count++)) + else + echo "It seems you don't have ${Binaries[$Count]} installed" + exit 1 fi done + +# Define functions print_usage() { $Printf "Usage: `basename $0` -H -o -h (help)\n"