Home » Infrastructure » Linux » Need Help for write script (linux )
Need Help for write script [message #593938] Thu, 22 August 2013 02:42 Go to next message
mahendra.s
Messages: 4
Registered: July 2013
Location: Bangalore
Junior Member

Hi all

I Need to write script to check oracle is accepting connection from application unix server to database unix server.
if accepting then connect to sqlplus and to verify procedure run call
if not,sleep 30mins and try again until 6 interval(total 3 hrs) and then exit and send mail

please help if any one know the script.

Thanks!
Re: Need Help for write script [message #593941 is a reply to message #593938] Thu, 22 August 2013 02:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Something like (not tested, please do it and post the final script):
for i in {1..6}
do
  sqlplus user/password@db <<EOF



exec your_procedure
exit
EOF
  if [ $? -eq 0 ]; then exit 0; fi
  sleep 1800
done
(echo "From: <sender email>"
 echo "To: <to email>"
 echo "Subject: <your subject>"
 echo "Content-Type: text/ascii"
 echo "Content-Disposition: inline"
 echo "<your text>"
 ) | sendmail <to email>
exit 1

Note: the 3 empty lines are mandatory, they are there to handle the case the database is not available.

Regards
Michel

[Edit: Add send mail]

[Updated on: Thu, 22 August 2013 02:57]

Report message to a moderator

Re: Need Help for write script [message #593956 is a reply to message #593941] Thu, 22 August 2013 04:53 Go to previous messageGo to next message
mahendra.s
Messages: 4
Registered: July 2013
Location: Bangalore
Junior Member

Hi Michel

thanks for our script..till not checked it.once i will tested i posted final script..

thanks!Smile
Re: Need Help for write script [message #593959 is a reply to message #593941] Thu, 22 August 2013 04:56 Go to previous messageGo to next message
sureshram24
Messages: 13
Registered: August 2013
Location: Bangalore
Junior Member
Hi Michael,

Thanks for your support and it helped me a lot.
I Know i can create a spool file inside sqlplus and then execute the procedure but is it possible to verify the procedure and print if any errors after execution?

Thanks & Regards
Suresh.R
Re: Need Help for write script [message #593960 is a reply to message #593959] Thu, 22 August 2013 05:01 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Yes, you can, for instance, do a "grep" on the spool file for any ORA- or SP2- strings.

Regards
Michel
Re: Need Help for write script [message #593966 is a reply to message #593960] Thu, 22 August 2013 05:17 Go to previous messageGo to next message
sureshram24
Messages: 13
Registered: August 2013
Location: Bangalore
Junior Member
Thank you so much. So can i use below checks to be done after the above code(oracle connection).

Procedure_checks()
{
      # Check for file existence
      if [ -f run_procedure.txt ]
       then
        print "\n run_procedure.txt found"

        # Obtain the number of error messages
        oract=`grep -c "ORA-" run_procedure.txt`
        spct=`grep -c "SP2-"  run_procedure.txt`
        errct=`grep -c -i "error" run_procedure.txt`

        # Report on the status of the log files
        if [ "$oract" = "0" ] && [ "$spct" = "0" ] && [ "$errct" = "0" ]
        then
         print "Appears to be good."
        else
         print "Appears to have a problem."
         ERR_FLAG=5
        fi

        # Regardless of errors print out the results
        print "      There are ($oract) Oracle errors"
        print "      There are ($spct) SQLPLUS errors"
        print "      There are ($errct) general errors"
      else
         print "**** Oracle Check Failed: Oracle log file not found ****"
         ERR_FLAG=6
      fi
     print "\n**** Oracle Check Complete ****"
     print "\n  "
}



[Edit MC: add code tags for readability]

[Updated on: Thu, 22 August 2013 06:55] by Moderator

Report message to a moderator

Re: Need Help for write script [message #593983 is a reply to message #593966] Thu, 22 August 2013 06:56 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Yes, something like that, now the usage will show you if you need some modification or not, this depends on your environment (organization and so).

Regards
Michel
Previous Topic: RAC and OCFS2
Next Topic: Maximum concurrent session per day
Goto Forum:
  


Current Time: Thu Apr 18 17:28:13 CDT 2024