echo "sqlplus output:" > /tmp/dbout.log
sqlplus 2>&1 | tee -a /tmp/dbout.log
echo "/u01/app/grid/19.3.0/gridhome_1/bin/sqlplus output:" >> /tmp/dbout.log
/u01/app/grid/19.3.0/gridhome_1/bin/sqlplus 2>&1 | tee -a /tmp/dbout.log
echo "/u01/app/grid/19.3.0/gridhome_1/bin/sqlplus perms:" >> /tmp/dbout.log
ls -l u01/app/grid/19.3.0/gridhome_1/bin/sqlplus 2>&1 | tee -a /tmp/dbout.log
As suggested, I have copy the provided data in .sh file and after running the script on Linux Oracle server. Below is the o/p from /tmp/dbout.log file.
root@agasporap1855 libexec]# cat /tmp/dbout.log
sqlplus output:
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Aug 13 08:39:16 2021
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Enter user-name: Enter password:
Last Successful login time: Wed Aug 11 2021 03:55:58 -04:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.10.0.0.0
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.10.0.0.0
/u01/app/grid/19.3.0/gridhome_1/bin/sqlplus output:
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Aug 13 08:39:52 2021
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Enter user-name:
Then I removed the /tmp/dbout.log file and then I ran the script from the Nagios server and below is the o/p.
bash-4.2$ /usr/local/nagios/libexec/check_nrpe -H 10.110.3.55 -t 30 -c DBconnection_status
/usr/local/nagios/libexec/check_dbconnection.sh: line 2: sqlplus: command not found
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
-rwxr-xr-x. 1 root oinstall 24800 Sep 18 2020 u01/app/grid/19.3.0/gridhome_1/bin/sqlplus
bash-4.2$
[root@agasporap1855 libexec]# cat /tmp/dbout.log
sqlplus output:
/usr/local/nagios/libexec/check_dbconnection.sh: line 2: sqlplus: command not found
/u01/app/grid/19.3.0/gridhome_1/bin/sqlplus output:
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
/u01/app/grid/19.3.0/gridhome_1/bin/sqlplus perms:
-rwxr-xr-x. 1 root oinstall 24800 Sep 18 2020 u01/app/grid/19.3.0/gridhome_1/bin/sqlplus
[root@agasporap1855 libexec]#