Example: biology

Shell Scripting for the Oracle Professional

Jon EmmonsShell Scripting for the Oracle ProfessionalShell Scripting for theOracle ProfessionalJon EmmonsOracle ConsultantAuthorJon EmmonsShell Scripting for the Oracle ProfessionalMy Background Undergraduate Computer Sciencecoursework. Extensive experience in Solaris and Linuxsystem administration. Oracle Database Administration onversions through 10gR2. As a consultant I must build efficient, low-to no-maintenance scripts for a variaety EmmonsShell Scripting for the Oracle ProfessionalBooks by Jon EmmonsOracle Shell Scripting : Linux &Unix Programming for OracleOn shelves this summerPre-order at Linux Commands: WorkingExamples of Linux Command SyntaxAvailable Today at Bookstoresand at EmmonsShell Scripting for the Oracle EmmonsShell Scripting for the Oracle ProfessionalWARNING: There are no one size fits all solutions.

Shell Scripting for the Oracle Professional Jon Emmons Books by Jon Emmons Oracle Shell Scripting: Linux & Unix Programming for Oracle On shelves this summer

Tags:

  Oracle, Professional, Shell, Scripting, Shell scripting for the oracle professional

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Shell Scripting for the Oracle Professional

1 Jon EmmonsShell Scripting for the Oracle ProfessionalShell Scripting for theOracle ProfessionalJon EmmonsOracle ConsultantAuthorJon EmmonsShell Scripting for the Oracle ProfessionalMy Background Undergraduate Computer Sciencecoursework. Extensive experience in Solaris and Linuxsystem administration. Oracle Database Administration onversions through 10gR2. As a consultant I must build efficient, low-to no-maintenance scripts for a variaety EmmonsShell Scripting for the Oracle ProfessionalBooks by Jon EmmonsOracle Shell Scripting : Linux &Unix Programming for OracleOn shelves this summerPre-order at Linux Commands: WorkingExamples of Linux Command SyntaxAvailable Today at Bookstoresand at EmmonsShell Scripting for the Oracle EmmonsShell Scripting for the Oracle ProfessionalWARNING: There are no one size fits all solutions.

2 You mustevaluate any techniques or solutions based on yourenvironments and goals Always test any solution in a non-productionenvironment before applying it to a production system. Make sure you completely understand new commandsand techniques before applying them in have been warned!Jon EmmonsShell Scripting for the Oracle ProfessionalTopics When to script Scripting Basics The Oracle connection Some useful tricks Troubleshooting Some ScriptsJon EmmonsShell Scripting for the Oracle ProfessionalWhen to ScriptJon EmmonsShell Scripting for the Oracle ProfessionalWhen To ScriptsShell Scripting can be applied to a widevariety of system and database called Scripting this isprogramming, but don t let that scare careful of script bloat. Be sensitive toyour coworkers and your EmmonsShell Scripting for the Oracle ProfessionalRepeated TasksNecessity is the mother of invention.

3 Thefirst candidates for Shell scripts will bemanual tasks which are done on a regularbasis. Backups Log monitoring Check disk spaceJon EmmonsShell Scripting for the Oracle ProfessionalOccasional TasksTasks which are performed rarely enoughthat their method, or even their need maybe forgotten. Periodic business related reports(monthly/quarterly/yearly) Offsite backups Purging old dataJon EmmonsShell Scripting for the Oracle ProfessionalComplex Manual TasksSome tasks must be performed manuallybut may be aided by Scripting . Checking for database locks Killing runaway processesThese tasks may evolve into repeated tasksJon EmmonsShell Scripting for the Oracle ProfessionalHelper ScriptsDon t ignore the usefulness of helper scripts. Perhaps a system administratorreally does need to look over the log for asystem daily, but a script can help byautomatically sending it on to him!

4 Jon EmmonsShell Scripting for the Oracle ProfessionalSpecial TasksThese are tasks which would not bepossible without a programming language. Storing OS information (performancestats, disk usage, etc.) into the database High frequency monitoring (several timesa day or more)Jon EmmonsShell Scripting for the Oracle ProfessionalScripting BasicsJon EmmonsShell Scripting for the Oracle ProfessionalBefore You Start ScriptingYou will find Shell Scripting an iterative process, but it isbest to have a good idea of your goals when you start. What are you trying to accomplish What are the dependencies Which dependencies can we check first Which dependencies cannot be checked How broad will the effects of this script be What happens if any step fails Should the script continue or be halted What results or output do we want from the script Who should be notified of the results and how What cleanup should be done when the script is complete What if two copies of the script get executed simultaneouslyJon EmmonsShell Scripting for the Oracle ProfessionalScripting ToolsAny plain text editor will work.

5 Vi (Command line UNIX) Notepad (Windows) TextEdit (Mac OSX) EditPlus (Windows, shareware, $30) EmmonsShell Scripting for the Oracle ProfessionalThe ShellShell Scripting allows us to use commandswe already use at the command considerably eases the are familiar with the interactive mode ofthe Shell . Almost anything can be done ina script which can be done at thecommand EmmonsShell Scripting for the Oracle ProfessionalWhich Shell to UseMy preference is Bash (bash) because of itsubiquity and compatibility with Bourne (sh).Other common shells include: C Shell (csh) Korn Shell (ksh) Z Shell (zsh)It is important to pick a Shell and stick with it. Thedifferences between shells are often small EmmonsShell Scripting for the Oracle ProfessionalThe Anatomy of a Commandgrep i localhost /etc/hostsCommand OptionArgumentsOptions change the behavior of a commandArguments control what the command acts uponJon EmmonsShell Scripting for the Oracle ProfessionalVariablesVariables are set using the = signORACLE_SID=ossVariables and their contents are case sensitive, sothe variable ORACLE_SID is different from thevariable variables are un-typed and may containintegers or with a decimal point will be treated astext.

6 ( )Jon EmmonsShell Scripting for the Oracle ProfessionalVariable Naming Variables should have meaningful names Variable names do not need to be short All UPPER CASE typically indicates anenvironmental variable Local (script) variables are conventionallyall lowercase Underscores (_) are best for separatingwords in variable namesJon EmmonsShell Scripting for the Oracle ProfessionalVariable Scope Variables will be available within the script(or Shell session) which sets them By exporting variables they can be madeavailable to subsequently called is why we typically perform anexport ORACLE_SIDafter setting the is not necessary when variableswill only be used within the current EmmonsShell Scripting for the Oracle ProfessionalUsing VariablesThe dollar sing ($) is used to retrieve the contentsof a variable.$ echo $ORACLE_SIDossIf you are trying to use a variable where it may besurrounded by other letters you may need toadd curly braces {} around the name.

7 $ echo ${ORACLE_SID}_sidoss_sidJon EmmonsShell Scripting for the Oracle ProfessionalComments and Whitespace Anything appearing after a pound symbol(#) on a line will be ignored. Adding comments can aid troubleshootingand future editing of the script. Blank lines are ignored when a script isexecuted. Blank lines and other whitespace (tabs,spaces) can be used to improve EmmonsShell Scripting for the Oracle ProfessionalA basic script#!/bin/bashecho "The current database is $ORACLE_SID"echo "The current running processes for$ORACLE_SID are"ps ef | grep $ORACLE_SIDJon EmmonsShell Scripting for the Oracle ProfessionalA basic script#!/bin/bashecho "The current database is $ORACLE_SID"echo "The current running processes for$ORACLE_SID are"ps ef | grep $ORACLE_SIDThis first line indicates whatinterpreter to use when runningthis scriptJon EmmonsShell Scripting for the Oracle ProfessionalA basic script#!

8 /bin/bashecho "The current database is $ORACLE_SID"echo "The current running processes for$ORACLE_SID are"ps ef | grep $ORACLE_SIDW hitespace is used toseparate commands toimprove EmmonsShell Scripting for the Oracle ProfessionalA basic script#!/bin/bashecho "The current database is $ORACLE_SID"echo "The current running processes for$ORACLE_SID are"ps ef | grep $ORACLE_SIDV ariables referenced heremust have already beenset and EmmonsShell Scripting for the Oracle ProfessionalA basic script#!/bin/bashecho "The current database is $ORACLE_SID"echo "The current running processes for$ORACLE_SID are"ps ef | grep $ORACLE_SIDNote the variable beingused as an 'll see a lot of EmmonsShell Scripting for the Oracle ProfessionalThe Shebang (#!)The "shebang" is a special comment. Sinceit is a comment it will not be executedwhen the script is run.

9 Instead before thescript is run, the Shell calling the script willcheck for the #! pattern. If found it willinvoke the script using that no #! is found most shells will use thecurrent Shell to run the EmmonsShell Scripting for the Oracle ProfessionalThe Shebang (cont)Since the shells are installed in different locationson different systems you may have to alter the#! line. For example, the bash Shell may be in/bin/bash, /usr/bin/bash or/usr/local/ the Shell explicitly like this assures that thescript will be run with the same interpreterregardless of who executes it (or what theirdefault Shell may be.)Jon EmmonsShell Scripting for the Oracle ProfessionalScript NamingDescriptive names are important. Use full words Separate words with underscores Avoid using spaces or other unusual characters There is no requirement for script names, buttypically they will end in.

10 ShTalk with others at your site who are doing shellscripting and try to agree on a EmmonsShell Scripting for the Oracle ProfessionalScript PermissionsThe execute permission must be turned on beforea script can be executed. It can be turned onfor the user (u), group (g) or all users (o) byusing the chmod ugo+x execute has not been granted you will get anerror like this:-bash: . : Permission deniedJon EmmonsShell Scripting for the Oracle #!/bin/sh# Show the user and host nameecho "Hello $USER!"echo "Welcome to `hostname`"echo "--- Current Disk Usage ---"df -h# On some systems the -h (human readable) option will not work with df# In that case you can use the -k option to display output in killobytesecho "--- Current uptime, users and load averages ---"uptimeecho "--- Load average numbers represent the 1, 5 and 15 minute loadaverages ---"echo "--- Lower numbers are better for load averages ---"# These are the first two things I check when I think there is a problem# with a system, but I'm sure you can think of some other things to addhereJon EmmonsShell Scripting for the Oracle #!


Related search queries