Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #!/bin/bash
  2. # Shell script to run sql files from command line.
  3. # Pre-Req: sqlplus client shall be installed already.
  4. ###########################################################
  5. # Variables Section (DB Details)
  6. ###########################################################
  7. driverClassName=oracle.jdbc.driver.OracleDriver
  8. url="(description=(address_list=(address=(protocol=TCP)(host=oradb.test.env.org)(port=1521)))(connect_data=(service_name=TEST_S)))"
  9. DB_UserName="abc"
  10. DB_Password="abc"
  11. LogDirectory="/var/tmp/logs"
  12. DataDirectory="/var/tmp/data"
  13. DB_HostName="oradb.test.env.org"
  14. DB_Port="1521"
  15. DB_SID="KONTOR"
  16. DIR_SqlFiles="C:gitsql"
  17. ##########################################################
  18. # All Script Functions Goes Here
  19. ##########################################################
  20.  
  21.  
  22. db_statuscheck() {
  23. echo "`date` :Checking DB connectivity...";
  24. echo "`date` :Trying to connect "${DB_UserName}"/"${DB_Password}"@"${DB_SID}" ..."
  25. echo "exit" | sqlplus -S ${DB_UserName}/${DB_Password}@${url} | grep -q "Connected to:" > /dev/null
  26. if [ $? -eq 0 ]
  27. then
  28. DB_STATUS="UP"
  29. export DB_STATUS
  30. echo "`date` :Status: ${DB_STATUS}. Able to Connect..."
  31. else
  32. DB_STATUS="DOWN"
  33. export DB_STATUS
  34. echo "`date` :Status: DOWN . Not able to Connect."
  35. echo "`date` :Not able to connect to database with Username: "${DB_UserName}" Password: "${DB_Password}" DB HostName: "${DB_HostName}" DB Port: "${DB_Port}" SID: "${DB_SID}"."
  36. echo "`date` :Exiting Script Run..."
  37. exit
  38. fi
  39. }
  40.  
  41. Main() {
  42. echo "`date` :Starting Sql auto run script."
  43. db_statuscheck
  44. echo "`date` :Sql auto run script execution completed."
  45. }
  46.  
  47. Main | tee autosql.log
  48.  
  49. 7. apr 2016 15:18:09 :Starting Sql auto run script.
  50. 7. apr 2016 15:18:09 :Checking DB connectivity...
  51. 7. apr 2016 15:18:09 :Trying to connect abc/abc@TEST_S ...
  52. 7. apr 2016 15:18:09 :Status: DOWN . Not able to Connect.
  53. 7. apr 2016 15:18:09 :Not able to connect to database with Username: abc abc Password: kjopsprosesser_utv4 DB HostName: oradb.test.env.orgDB Port: 1521 SID: TEST_S
  54. 7. apr 2016 15:18:09 :Exiting Script Run...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement