Created
May 6, 2010 20:09
-
-
Save sms420/392641 to your computer and use it in GitHub Desktop.
ora_info.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr//bin/env ruby | |
| ################################# | |
| # ora_info.rb | |
| # Sean Stephenson | |
| # 2010-05-05 | |
| # a script that tells you the path of: | |
| # > table space names [-t] | |
| # > redo log files [-r] | |
| # > control files [-c] | |
| # > spfile [-s] | |
| # > pfile (init.ora) [-p] | |
| # | |
| # CS151B (Oracle Database Admin) | |
| # Prof: Abbas | |
| ################################# | |
| ########## do_oracle ########## | |
| def do_oracle(sql) | |
| sql.chop! if sql[-1] == ';' | |
| cmd = <<-EOJ | |
| sqlplus -S system/manager <<-EOF | |
| set echo off head off pagesize 0 | |
| #{sql}; | |
| set echo on head on pagesize 24 | |
| quit | |
| EOF | |
| EOJ | |
| done = system(cmd) | |
| abort("access to Oracle failed\n") unless done | |
| end | |
| ########## tablespace_names_and_path ########## | |
| def tablespace_names_and_path | |
| puts "tablespace names and path:" | |
| str = "select file_name, tablespace_name from dba_data_files;" | |
| do_oracle(str) | |
| end | |
| ########## redologfile_names_and_path ########## | |
| def redologfile_names_and_path | |
| puts "redologfile names and path:" | |
| str = "select * from v\\$logfile" | |
| do_oracle(str) | |
| end | |
| ########## controlfile_path ########## | |
| def controlfile_path | |
| puts "control file path" | |
| str = "select name from v\\$controlfile" | |
| do_oracle(str) | |
| end | |
| ########## spfile_path ########## | |
| def spfile_path | |
| puts "spfile path:" | |
| str = "select value from v\\$parameter where name='spfile';" | |
| do_oracle(str) | |
| end | |
| ########## pfile_path ########## | |
| def pfile_path | |
| puts "pfile (init.ora) path:" | |
| result = `find $ORACLE_HOME -name init.ora 2>/dev/null` | |
| puts result | |
| end | |
| ########## usage ########## | |
| def usage | |
| puts " USAGE | |
| [-t]: tablespace_names_and_path | |
| [-r]: redlogfile_names_and_path | |
| [-c]: controlfile_path | |
| [-s]: spfile_path | |
| [-p]: pfile_path | |
| [-h]: usage" | |
| end | |
| ########## get_input ########## | |
| def get_input | |
| case ARGV[0] | |
| when "-t" then tablespace_names_and_path | |
| when "-r" then redologfile_names_and_path | |
| when "-c" then controlfile_path | |
| when "-s" then spfile_path | |
| when "-p" then pfile_path | |
| when "-h" then usage | |
| else usage | |
| end | |
| end | |
| get_input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment