Re: bash scripting with many ifs not working
Posted: Wed Feb 03, 2016 2:45 pm
here is the odd thing
i removed all the ifs in the bash..the script only contains is this now
==================================
on the command line : i get this
[nagios@tbv1nagios8 oracle]$ ./scriptsqlplus.sh -s mon_nb_users.sql -i dora80 -u nagios -b 398
398
[nagios@tbv1nagios8 oracle]$
however one the nagios side i get what you see as screenshot.
(No output returned from plugin)
if i dont trim the spaces the output is something like this
[nagios@tbv1nagios8 oracle]$ . Oracle.env;sqlplus -s nagios/xxx@dora80 @mon_nb_users.sql
398
tbv1nagios8:nagios$
perhaps trimming the spaces is not the best idea.
i removed all the ifs in the bash..the script only contains is this now
Code: Select all
#!/bin/bash
#coded by ajdazeve
# version 3.2
script=""
instance=""
warn=0
crit=0
stactic=0
dis=0
user=""
pass=""
# Get options
while getopts :i:s:w:c:d:b:u: OPTION
do
case $OPTION
in
i)
instance=${OPTARG}
;;
s)
script=${OPTARG}
;;
w)
warn=${OPTARG}
;;
c)
crit=${OPTARG}
;;
b)
stactic=${OPTARG}
;;
d)
dis=${OPTARG}
;;
u)
user=${OPTARG}
;;
esac
done
# grab password from User
pass=$(awk -F "$user"= '{print $2}' .mdfpassword )
# extract output from query
tmp_out_nospace=$(. Oracle.env;sqlplus -s "$user"/"$pass"@$instance @$script | tr -d '[[:space:]]' )
echo $tmp_out_nospace
#tmp_out_nospace="$(echo -e "${tmp_out}" | tr -d '[[:space:]]')"
#output="result: "$tmp_out" "
# show all variables for debugging
#echo $script
#echo $instance
#echo $warn
#echo $crit
#echo $stactic
#echo $dis
#echo $tmp_out
#echo $tmp_out_nospace
#echo $output
#echo $errcnt
#echo $user
#echo $passon the command line : i get this
[nagios@tbv1nagios8 oracle]$ ./scriptsqlplus.sh -s mon_nb_users.sql -i dora80 -u nagios -b 398
398
[nagios@tbv1nagios8 oracle]$
however one the nagios side i get what you see as screenshot.
(No output returned from plugin)
if i dont trim the spaces the output is something like this
[nagios@tbv1nagios8 oracle]$ . Oracle.env;sqlplus -s nagios/xxx@dora80 @mon_nb_users.sql
398
tbv1nagios8:nagios$
perhaps trimming the spaces is not the best idea.