当我尝试使用Nagios GUI中的脚本时,它不起作用,而它来自CLI。
这是我的剧本
#!/bin/bash
sqlplus='/usr/lib/oracle/11.2/client64/bin/sqlplus'
TMPFILE='/usr/local/nagios/.DBStatus/TMP.out'
IP=$1
DBCREDS=$2
#Check the DB Host is UP / NOT
HOSTALIVE=$(ping -c 1 $IP | grep icmp | wc -l)
if [ $HOSTALIVE -eq 0 ]
then
echo " Host "$IP" is not reachable, Please check the connectivity "
exit 2;
fi
# DB Check
$sqlplus $DBCREDS <<STORE > $TMPFILE
select count(*) from user_tables;
exit;
STORE
CMD=`cat $TMPFILE`
if grep -Fq "Connected to" <<< $CMD;
then
echo "DB Connection is OK"
exit 0;
else
echo "DB Connection is Down"
exit 2;
fi
exit 0;
脚本检查模式以查看数据库是否能够连接。
我不确定出了什么问题......它可以在CLI中运行
[cobnmon011] ~/.DBStatus $ bash /usr/local/nagios/libexec/check_oradbstatus.sh xyz.com 'admin_123/xyzabcd@abcd'
数据库连接正常
但是从Nagios GUI显示为“DB Connection is Down”。
谢谢