Home » Infrastructure » Linux » Shell script to check Oracle Availability (Oracle 11g, 11.2.0.4, linux 6.9)
Shell script to check Oracle Availability [message #674020] Thu, 27 December 2018 00:38 Go to next message
nomannishat
Messages: 11
Registered: September 2007
Location: PAKISTAN
Junior Member

Dear Friends,

I am looking for shell script that script check the database up or not if not then send the email, does any one have. Please share
Re: Shell script to check Oracle Availability [message #674021 is a reply to message #674020] Thu, 27 December 2018 00:56 Go to previous messageGo to next message
Michel Cadot
Messages: 68722
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

1/ Try to connect with sqlplus:
echo 'exit' | sqlplus -l foo/bar@db
2/ Check return code $?, if not 0 send mail

Re: Shell script to check Oracle Availability [message #674023 is a reply to message #674021] Thu, 27 December 2018 01:46 Go to previous messageGo to next message
nomannishat
Messages: 11
Registered: September 2007
Location: PAKISTAN
Junior Member

Hi,
thanks i want to write script like that


echo "`date` "
echo "Oracle Database(s) Status `hostname` :\n"


pslist="`ps -ef | grep pmon`"
echo "$pslist" | grep "ora_pmon_$pslist" > /dev/null 2>$1
if "$pslist" | grep "ora_pmon_$pslist" is null > /dev/null 2>$1
then
echo "Oracle Instance - $pslist: Down"
else
echo "Oracle Instance - $pslist: Up"
fi

Re: Shell script to check Oracle Availability [message #674024 is a reply to message #674023] Thu, 27 December 2018 02:49 Go to previous messageGo to next message
Michel Cadot
Messages: 68722
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

So what is the problem then?

Please read How to use [code] tags and make your code easier to read.

Re: Shell script to check Oracle Availability [message #674025 is a reply to message #674023] Thu, 27 December 2018 03:13 Go to previous messageGo to next message
nomannishat
Messages: 11
Registered: September 2007
Location: PAKISTAN
Junior Member

see the results.

[oracle@hostname ~]$ sh db1.sh
Thu Dec 27 14:10:32 PKT 2018
Oracle Database(s) Status newtest-db :\n
db1.sh: line 6: $1: ambiguous redirect
db1.sh: line 7: oracle 48883 1 0 14:04 ? 00:00:00 ora_pmon_dbse
oracle 49550 49548 0 14:10 pts/3 00:00:00 grep pmon: No such file or directory
db1.sh: line 7: $1: ambiguous redirect
Oracle Instance - oracle 48883 1 0 14:04 ? 00:00:00 ora_pmon_dbse
oracle 49550 49548 0 14:10 pts/3 00:00:00 grep pmon: Up
[oracle@hostname ~]$ vi db1.sh
[oracle@hostname ~]$

its showing database is up but if database is down so how it would capture?
Re: Shell script to check Oracle Availability [message #674026 is a reply to message #674025] Thu, 27 December 2018 03:14 Go to previous messageGo to next message
nomannishat
Messages: 11
Registered: September 2007
Location: PAKISTAN
Junior Member

when i shutdow the database its showing below

[oracle@localhost ~]$ sh db1.sh
Thu Dec 27 14:13:28 PKT 2018
Oracle Database(s) Status newtest-db :\n
db1.sh: line 6: $1: ambiguous redirect
db1.sh: line 7: oracle 49781 49779 0 14:13 pts/3 00:00:00 grep pmon: No such file or directory
db1.sh: line 7: $1: ambiguous redirect
Oracle Instance - oracle 49781 49779 0 14:13 pts/3 00:00:00 grep pmon: Up
[oracle@localhost ~]$

Re: Shell script to check Oracle Availability [message #674031 is a reply to message #674026] Thu, 27 December 2018 10:25 Go to previous message
Michel Cadot
Messages: 68722
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

You need to have somewhere the list of instances you want to check, it could /etc/oratab and loop on them to check if pmon exists.

Previous Topic: ORA-01994: GRANT failed: password file missing or disabled
Next Topic: Perfect Linux Installations
Goto Forum:
  


Current Time: Wed Dec 11 14:11:34 CST 2024