UNIX Shell Scripting

52
* Solutions. Powered by people. February 8, 2001 Scripting in the UNIX Environment to Support Oracle Bill Ducat • (888) 775-3778 x227 [email protected]

Transcript of UNIX Shell Scripting

Page 1: UNIX Shell Scripting

* Solutions. Powered by people.

February 8, 2001

Scripting in the UNIX Environment to Support Oracle

Bill Ducat • (888) 775-3778 x227 [email protected]

Page 2: UNIX Shell Scripting

* Solutions. Powered by people.

BUILDING BLOCKS

STDOUTSTDOUT STDERRSTDERR STDINSTDIN Environment VariablesEnvironment Variables ScriptsScripts

Page 3: UNIX Shell Scripting

* Solutions. Powered by people.

STDOUT

Most commands send output to Most commands send output to the screenthe screen

You can redirect output using the You can redirect output using the > and >> redirectors> and >> redirectors

The “tee” command can be used The “tee” command can be used to send results to the screen as to send results to the screen as well as a filewell as a file

Page 4: UNIX Shell Scripting

* Solutions. Powered by people.

STDERR

STDERR is the destination of STDERR is the destination of error informationerror information

Most commands redirect Most commands redirect STDERR to the screenSTDERR to the screen

It can be redirected to a file using It can be redirected to a file using 2><2><filename>filename>

It can be redirected to the same It can be redirected to the same place as STDOUT using 2>&1place as STDOUT using 2>&1

Page 5: UNIX Shell Scripting

* Solutions. Powered by people.

PUTTING THEM TOGETHER

ls myfile* >results.txt 2>errors.txtls myfile* >results.txt 2>errors.txtoror

ls myfile* >results.txt 2>&1ls myfile* >results.txt 2>&1

Page 6: UNIX Shell Scripting

* Solutions. Powered by people.

STDIN

STDIN is the source of input for a STDIN is the source of input for a commandcommand

It usually comes from the It usually comes from the keyboard or from the results of keyboard or from the results of another commandanother command

The pipe “|” is used to set the The pipe “|” is used to set the results of one command as the results of one command as the input to another commandinput to another command

Page 7: UNIX Shell Scripting

* Solutions. Powered by people.

STDIN - PIPING RESULTS

sort myfilesort myfileDoes the same thing as Does the same thing as

cat myfile |sortcat myfile |sort

Page 8: UNIX Shell Scripting

* Solutions. Powered by people.

STDIN - PIPING RESULTS (cont.)

Grep “ORA-” myfile|sed –e Grep “ORA-” myfile|sed –e ‘s/^‘s/^ ��*//;s/^/ *//;s/^/ � � � � � � /’|sort/’|sort

Looks for ORA- in myfileLooks for ORA- in myfile For each line found, it replaces For each line found, it replaces

any number of spaces at the any number of spaces at the beginning of the line with 3 beginning of the line with 3 spacesspaces

Sorts the resultsSorts the results

Page 9: UNIX Shell Scripting

* Solutions. Powered by people.

STDIN – Keyboard Simulation

sqlplus scott/tiger –s <<!!sqlplus scott/tiger –s <<!! select * from global_name;select * from global_name; quit;quit; !!!! Nothing executes until the final Nothing executes until the final

return is pressedreturn is pressed Nothing can follow the “!!” On a Nothing can follow the “!!” On a

lineline

Page 10: UNIX Shell Scripting

* Solutions. Powered by people.

Environment Variables

The “env” command shows all The “env” command shows all environment variables that have environment variables that have been exportedbeen exported

Variables are referenced by Variables are referenced by placing a “$” in front of the placing a “$” in front of the variable namevariable name

““{}” should enclose every {}” should enclose every reference to a variablereference to a variable

Page 11: UNIX Shell Scripting

* Solutions. Powered by people.

Environment Variables (cont.)

echo $ORACLE_SIDecho $ORACLE_SIDProduces the same result asProduces the same result as

echo ${ORACLE_SID}echo ${ORACLE_SID}

Page 12: UNIX Shell Scripting

* Solutions. Powered by people.

Environment Variables (cont.)

echo $ORACLE_SID_worldecho $ORACLE_SID_worldDoes not do the same thing asDoes not do the same thing as

echo ${ORACLE_SID}_worldecho ${ORACLE_SID}_world

Page 13: UNIX Shell Scripting

* Solutions. Powered by people.

Environment Variables (cont.)

SYSTEM_CONNECT=system/managerSYSTEM_CONNECT=system/managerSqlplus ${SYSTEM_CONNECT}Sqlplus ${SYSTEM_CONNECT}

Page 14: UNIX Shell Scripting

* Solutions. Powered by people.

*** WARNINGS ***

The export command can be used to The export command can be used to increase the scope of environment increase the scope of environment variables.variables.

Exported environment variables can Exported environment variables can be seen by other users using the “ps be seen by other users using the “ps aew” command.aew” command.

Do not place passwords in exported Do not place passwords in exported environment variables!environment variables!

Page 15: UNIX Shell Scripting

* Solutions. Powered by people.

Scripts Simple scripts are nothing more than Simple scripts are nothing more than

a series of commandsa series of commands There are various shells, but we will There are various shells, but we will

use the KORN shelluse the KORN shell Use vi, or some lesser editor Use vi, or some lesser editor , to , to

create scriptscreate scripts Use the chmod command to add Use the chmod command to add

execute permissions to the fileexecute permissions to the file chmod +x myfile.kshchmod +x myfile.ksh

Page 16: UNIX Shell Scripting

* Solutions. Powered by people.

Scripts (cont.)

Simple script: Simple script: datedatepwdpwdwhoamiwhoami

Page 17: UNIX Shell Scripting

* Solutions. Powered by people.

Scripts – Parameter Passing

Parameters can be treated like Parameters can be treated like environment variables within a environment variables within a scriptscript

Special parameter variables can Special parameter variables can be used to get information about be used to get information about parametersparameters

Page 18: UNIX Shell Scripting

* Solutions. Powered by people.

Scripts – Parameter Variables

$1 – The first parameter$1 – The first parameter $2 – The second parameter$2 – The second parameter $0 – The command without $0 – The command without

parametersparameters $# - The number of parameters $# - The number of parameters

passed inpassed in

Page 19: UNIX Shell Scripting

* Solutions. Powered by people.

Scripts – Sample

#! /bin/ksh#! /bin/kshecho $1echo $1echo $2echo $2echo $#echo $#echo $0echo $0echo Doneecho Done

Page 20: UNIX Shell Scripting

* Solutions. Powered by people.

Scripts – Functions

#! /bin/ksh#! /bin/ksh__doit ()__doit (){{echo $1 $2echo $1 $2}}echo $1 $2echo $1 $2__doit test $1__doit test $1

Page 21: UNIX Shell Scripting

* Solutions. Powered by people.

Scripts – IF Processing

x=5x=5if ( test ${X} –gt 0 ) ;thenif ( test ${X} –gt 0 ) ;then echo ${x} is greater than 0echo ${x} is greater than 0elseelse echo ${x} is less than 0echo ${x} is less than 0fifi

Page 22: UNIX Shell Scripting

* Solutions. Powered by people.

Scripts – FOR Processing

for x in a b c ;dofor x in a b c ;do echo ${x}echo ${x}donedone

for x in ‘ls’ ;dofor x in ‘ls’ ;do lp ${x}lp ${x}done done

Page 23: UNIX Shell Scripting

* Solutions. Powered by people.

Scripts – Process IDs

The “$$” variable will identify The “$$” variable will identify your process IDyour process ID

This can be used to create This can be used to create unique file namesunique file namesls >my_results_$$.outls >my_results_$$.out

Page 24: UNIX Shell Scripting

* Solutions. Powered by people.

Practical Examples

We will build a script that will We will build a script that will display session information for display session information for all instances on a machine. This all instances on a machine. This script will demonstrate:script will demonstrate: Password ManagementPassword Management Embedded SQLEmbedded SQL Embedded SubroutinesEmbedded Subroutines Parameter PassingParameter Passing

Page 25: UNIX Shell Scripting

* Solutions. Powered by people.

PASSWORD FILE

The file setup_passwords.ksh The file setup_passwords.ksh contains environment variables contains environment variables defining passwordsdefining passwords

The system password is the The system password is the same on each instancesame on each instance

The file must be protected from The file must be protected from non DBA usersnon DBA users

Page 26: UNIX Shell Scripting

* Solutions. Powered by people.

SAMPLE PASSWORD FILE

SYSTEM_CONNECT=system/managerSYSTEM_CONNECT=system/managerSYS_CONNECT=sys/change_on_installSYS_CONNECT=sys/change_on_installDUCAT_CONNECT=wducat/catDUCAT_CONNECT=wducat/cat

Page 27: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 1

#! /bin/ksh#! /bin/ksh. /common/bin/setup_passwords.ksh. /common/bin/setup_passwords.ksh$ORACLE_HOME/bin/sqlplus -s /nolog <<!!$ORACLE_HOME/bin/sqlplus -s /nolog <<!!set line 200set line 200set feedback offset feedback offconnect ${SYSTEM_CONNECT};connect ${SYSTEM_CONNECT};column global_name heading "Instance" format a15column global_name heading "Instance" format a15column sessions_max heading "Max" format 9999column sessions_max heading "Max" format 9999column sessions_warning heading "Warning" format 9999column sessions_warning heading "Warning" format 9999column sessions_current heading "Current" format 9999column sessions_current heading "Current" format 9999column sessions_highwater heading "Highwater" format 9999column sessions_highwater heading "Highwater" format 9999selectselect global_name,sessions_max,sessions_warning,global_name,sessions_max,sessions_warning, sessions_current-1 sessions_current,sessions_current-1 sessions_current, sessions_highwatersessions_highwaterfromfrom v\$license,global_name ;v\$license,global_name ;quit;quit;!!!!

Page 28: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 1 Results

Connected.Connected.  Instance Max Warning Current HighwaterInstance Max Warning Current Highwater--------------- ----- ------- ------- ------------------------ ----- ------- ------- ---------DEVEL.WORLDDEVEL.WORLD 0 0 0 0 0 0

11

Page 29: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 2

#! /bin/ksh#! /bin/ksh. /common/bin/setup_passwords.ksh. /common/bin/setup_passwords.ksh  __show_licenses()__show_licenses(){{$ORACLE_HOME/bin/sqlplus -s /nolog <<!!$ORACLE_HOME/bin/sqlplus -s /nolog <<!!set line 200set line 200set feedback offset feedback offconnect ${SYSTEM_CONNECT};connect ${SYSTEM_CONNECT};column global_name heading "Instance" format a15column global_name heading "Instance" format a15column sessions_max heading "Max" format 9999column sessions_max heading "Max" format 9999column sessions_warning heading "Warning" format 9999column sessions_warning heading "Warning" format 9999column sessions_current heading "Current" format 9999column sessions_current heading "Current" format 9999column sessions_highwater heading "Highwater" format 9999column sessions_highwater heading "Highwater" format 9999  

Page 30: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 2 (Cont.)

select select global_name,sessions_max,sessions_warning,global_name,sessions_max,sessions_warning, sessions_current-1 sessions_current,sessions_current-1 sessions_current, sessions_highwatersessions_highwaterfrom from v\$license,global_name ;v\$license,global_name ;quit;quit;!!!!}}  __show_licenses __show_licenses

Page 31: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 2 Results

Connected.Connected.  Instance Max Warning Current HighwaterInstance Max Warning Current Highwater--------------- ----- ------- ------- ------------------------ ----- ------- ------- ---------DEVEL.WORLDDEVEL.WORLD 0 0 0 0 0 0

11

Page 32: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 3

#! /bin/ksh#! /bin/ksh. /common/bin/setup_passwords.ksh. /common/bin/setup_passwords.ksh  __show_licenses()__show_licenses(){{$ORACLE_HOME/bin/sqlplus -s /nolog <<!!$ORACLE_HOME/bin/sqlplus -s /nolog <<!!set line 200set line 200set feedback offset feedback offconnect ${SYSTEM_CONNECT};connect ${SYSTEM_CONNECT};column global_name heading "Instance" format a15column global_name heading "Instance" format a15column sessions_max heading "Max" format 9999column sessions_max heading "Max" format 9999column sessions_warning heading "Warning" format 9999column sessions_warning heading "Warning" format 9999column sessions_current heading "Current" format 9999column sessions_current heading "Current" format 9999column sessions_highwater heading "Highwater" format 9999column sessions_highwater heading "Highwater" format 9999

Page 33: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 3 (Cont.)

select select global_name,sessions_max,sessions_warning,global_name,sessions_max,sessions_warning, sessions_current-1 sessions_current,sessions_current-1 sessions_current, sessions_highwatersessions_highwaterfrom from v\$license,global_name ; v\$license,global_name ; quit;quit;!!!!}}  __show_licenses | grep –v “^Connected\.$”__show_licenses | grep –v “^Connected\.$”

Page 34: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 3 Results

Instance Max Warning Current HighwaterInstance Max Warning Current Highwater--------------- ----- ------- ------- ------------------------ ----- ------- ------- ---------DEVEL.WORLDDEVEL.WORLD 0 0 0 0 0 0

11

Page 35: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 4

#! /bin/ksh#! /bin/ksh. /common/bin/setup_passwords.ksh. /common/bin/setup_passwords.ksh  __show_licenses()__show_licenses(){{$ORACLE_HOME/bin/sqlplus -s /nolog <<!!$ORACLE_HOME/bin/sqlplus -s /nolog <<!!set line 200set line 200set feedback offset feedback offconnect ${SYSTEM_CONNECT}@${1};connect ${SYSTEM_CONNECT}@${1};column global_name heading "Instance" format a15column global_name heading "Instance" format a15column sessions_max heading "Max" format 9999column sessions_max heading "Max" format 9999column sessions_warning heading "Warning" format 9999column sessions_warning heading "Warning" format 9999column sessions_current heading "Current" format 9999column sessions_current heading "Current" format 9999column sessions_highwater heading "Highwater" format 9999column sessions_highwater heading "Highwater" format 9999

Page 36: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 4 (Cont.)

select select global_name,sessions_max,sessions_warning,global_name,sessions_max,sessions_warning, sessions_current-1 sessions_current,sessions_current-1 sessions_current, sessions_highwatersessions_highwaterfrom from v\$license,global_name ; v\$license,global_name ; quit;quit;!!!!}}  __show_licenses ${1}| grep –v “^Connected\.$”__show_licenses ${1}| grep –v “^Connected\.$”

Page 37: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 4 Results

If the first parameter passed was “systest”:If the first parameter passed was “systest”:

  Instance Max Warning Current HighwaterInstance Max Warning Current Highwater--------------- ----- ------- ------- ------------------------ ----- ------- ------- ---------SYSTEST.WORLD 0SYSTEST.WORLD 0 0 0 0 0

11

Page 38: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 5

#! /bin/ksh#! /bin/ksh. /common/bin/setup_passwords.ksh. /common/bin/setup_passwords.ksh  __show_licenses()__show_licenses(){{$ORACLE_HOME/bin/sqlplus -s /nolog <<!!$ORACLE_HOME/bin/sqlplus -s /nolog <<!!set line 200set line 200set feedback offset feedback offconnect ${SYSTEM_CONNECT}@${1};connect ${SYSTEM_CONNECT}@${1};column global_name heading "Instance" format a15column global_name heading "Instance" format a15column sessions_max heading "Max" format 9999column sessions_max heading "Max" format 9999column sessions_warning heading "Warning" format 9999column sessions_warning heading "Warning" format 9999column sessions_current heading "Current" format 9999column sessions_current heading "Current" format 9999column sessions_highwater heading "Highwater" format 9999column sessions_highwater heading "Highwater" format 9999

Page 39: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 5 (Cont.)

select select global_name,sessions_max,sessions_warning,global_name,sessions_max,sessions_warning, sessions_current-1 sessions_current,sessions_current-1 sessions_current, sessions_highwatersessions_highwaterfrom from v\$license,global_name ; v\$license,global_name ; quit;quit;!!!!}}  if [ $# -ne 1 ] ;thenif [ $# -ne 1 ] ;then __show_licenses ${1}| grep –v “^Connected\.$”__show_licenses ${1}| grep –v “^Connected\.$”elseelse echo “ERROR: Invalid number of parameters specified”echo “ERROR: Invalid number of parameters specified” echo “ One instance name must be specified.”echo “ One instance name must be specified.”fifi

Page 40: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 5 Results

If the no parameter was passed:If the no parameter was passed:

  ERROR: Invalid number of parameters specifiedERROR: Invalid number of parameters specified One instance name must be specified.One instance name must be specified.

Page 41: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 6

#! /bin/ksh#! /bin/ksh. /common/bin/setup_passwords.ksh. /common/bin/setup_passwords.ksh  __show_licenses()__show_licenses(){{$ORACLE_HOME/bin/sqlplus -s /nolog <<!!$ORACLE_HOME/bin/sqlplus -s /nolog <<!!set line 200set line 200set feedback offset feedback offconnect ${SYSTEM_CONNECT}@${1};connect ${SYSTEM_CONNECT}@${1};column global_name heading "Instance" format a15column global_name heading "Instance" format a15column sessions_max heading "Max" format 9999column sessions_max heading "Max" format 9999column sessions_warning heading "Warning" format 9999column sessions_warning heading "Warning" format 9999column sessions_current heading "Current" format 9999column sessions_current heading "Current" format 9999column sessions_highwater heading "Highwater" format 9999column sessions_highwater heading "Highwater" format 9999

Page 42: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 6 (Cont.)

select select global_name,sessions_max,sessions_warning,global_name,sessions_max,sessions_warning, sessions_current-1 sessions_current,sessions_current-1 sessions_current, sessions_highwatersessions_highwaterfrom from v\$license,global_name ; v\$license,global_name ; quit;quit;!!!!}}  __show_licenses prod| grep –v “^Connected\.$”__show_licenses prod| grep –v “^Connected\.$”__show_licenses devel| grep –v “^Connected\.$”__show_licenses devel| grep –v “^Connected\.$”

Page 43: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 6 Results

Instance Max Warning Current HighwaterInstance Max Warning Current Highwater--------------- ----- ------- ------- ------------------------ ----- ------- ------- ---------PROD.WORLD 0 0 0PROD.WORLD 0 0 0 1 1  Instance Max Warning Current HighwaterInstance Max Warning Current Highwater--------------- ----- ------- ------- ------------------------ ----- ------- ------- ---------DEVEL.WORLD 0 0 0 DEVEL.WORLD 0 0 0

11

Page 44: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 7

#! /bin/ksh#! /bin/ksh. /common/bin/setup_passwords.ksh. /common/bin/setup_passwords.ksh  __show_licenses()__show_licenses(){{$ORACLE_HOME/bin/sqlplus -s /nolog <<!!$ORACLE_HOME/bin/sqlplus -s /nolog <<!!  set line 200set line 200set feedback offset feedback offset heading ${heading}set heading ${heading}connect ${SYSTEM_CONNECT}@${1};connect ${SYSTEM_CONNECT}@${1};column global_name heading "Instance" format a15column global_name heading "Instance" format a15column sessions_max heading "Max" format 9999column sessions_max heading "Max" format 9999column sessions_warning heading "Warning" format 9999column sessions_warning heading "Warning" format 9999column sessions_current heading "Current" format 9999column sessions_current heading "Current" format 9999column sessions_highwater heading "Highwater" format 9999column sessions_highwater heading "Highwater" format 9999select select global_name,sessions_max,sessions_warning,global_name,sessions_max,sessions_warning, sessions_current-1 sessions_current,sessions_current-1 sessions_current, sessions_highwatersessions_highwater

Page 45: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 7 (Cont.)

from from v\$license,global_name ;v\$license,global_name ;quit;quit;!!!!}}  heading=onheading=on__show_licenses prod|grep -vE "^Connected\.$|^$"__show_licenses prod|grep -vE "^Connected\.$|^$"heading=offheading=off__show_licenses devel|grep -vE "^Connected\.$|^$"__show_licenses devel|grep -vE "^Connected\.$|^$"__show_licenses systest|grep -vE "^Connected\.$|^$"__show_licenses systest|grep -vE "^Connected\.$|^$"

Page 46: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 7 Results

Instance Max Warning Current HighwaterInstance Max Warning Current Highwater--------------- ----- ------- ------- ------------------------ ----- ------- ------- ---------PROD.WORLD 0 0 0 1PROD.WORLD 0 0 0 1DEVEL.WORLD 0 0 0 1DEVEL.WORLD 0 0 0 1SYSTEST.WORLD 0 0 0 1SYSTEST.WORLD 0 0 0 1

Page 47: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 8

%ps -aef |grep ora_pmon_%ps -aef |grep ora_pmon_oracle 863 1 0 09:11 ? 00:00:00 ora_pmon_develoracle 863 1 0 09:11 ? 00:00:00 ora_pmon_develoracle 888 1 0 09:11 ? 00:00:00 ora_pmon_prodoracle 888 1 0 09:11 ? 00:00:00 ora_pmon_prodoracle 913 1 0 09:11 ? 00:00:00 ora_pmon_systestoracle 913 1 0 09:11 ? 00:00:00 ora_pmon_systestwducat 2584 2582 0 16:28 tty1 00:00:00 grep wducat 2584 2582 0 16:28 tty1 00:00:00 grep

ora_pmon_ora_pmon_%ps -aef |grep ora_pmon_ |grep -v grep%ps -aef |grep ora_pmon_ |grep -v greporacle 863 1 0 09:11 ? 00:00:00 ora_pmon_develoracle 863 1 0 09:11 ? 00:00:00 ora_pmon_develoracle 888 1 0 09:11 ? 00:00:00 ora_pmon_prodoracle 888 1 0 09:11 ? 00:00:00 ora_pmon_prodoracle 913 1 0 09:11 ? 00:00:00 ora_pmon_systestoracle 913 1 0 09:11 ? 00:00:00 ora_pmon_systest%ps -aef | grep ora_pmon_ | grep -vE 'sed|grep'| \%ps -aef | grep ora_pmon_ | grep -vE 'sed|grep'| \ sed -e 's/^.*ora_pmon_//'sed -e 's/^.*ora_pmon_//'develdevelprodprodsystestsystest%%

Page 48: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 9

11 #! /bin/ksh#! /bin/ksh2233 gen_sid_list()gen_sid_list()44 {{5566 sid_list=""sid_list=""77 touch /tmp/sids_$$.outtouch /tmp/sids_$$.out88 ps -aef | \ps -aef | \99 grep ora_pmon | \ grep ora_pmon | \1010 grep -vE 'sed|grep'| \ grep -vE 'sed|grep'| \1111 sed -e "s/^.*ora_pmon_//" \ sed -e "s/^.*ora_pmon_//" \1212 >/tmp/sids_$$.out >/tmp/sids_$$.out1313  

Page 49: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 9 (Cont.)

1414 for iName in `sort /tmp/sids_$$.out` ;dofor iName in `sort /tmp/sids_$$.out` ;do1515 tnsping ${iName} >/tmp/ping_$$.out tnsping ${iName} >/tmp/ping_$$.out1616 eCount=`grep TNS- /tmp/ping_$$.out|wc -l` eCount=`grep TNS- /tmp/ping_$$.out|wc -l`1717 if [ $eCount -eq 0 ] ;then if [ $eCount -eq 0 ] ;then1818 sid_list="${sid_list} ${iName}" sid_list="${sid_list} ${iName}"1919 else else2020 echo ERROR: Unable to connect to ${iName} echo ERROR: Unable to connect to ${iName}2121 fi fi2222 rm /tmp/ping_$$.out rm /tmp/ping_$$.out2323 donedone2424 rm /tmp/sids_$$.outrm /tmp/sids_$$.out2525 }}  

Page 50: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 10

#! /bin/ksh#! /bin/ksh. /common/bin/setup_passwords.ksh. /common/bin/setup_passwords.ksh. /common/bin/functions.ksh. /common/bin/functions.ksh  __show_licenses()__show_licenses(){{$ORACLE_HOME/bin/sqlplus -s /nolog <<!!$ORACLE_HOME/bin/sqlplus -s /nolog <<!!set line 200set line 200set feedback offset feedback offset heading ${heading}set heading ${heading}connect ${SYSTEM_CONNECT}@${1};connect ${SYSTEM_CONNECT}@${1};column global_name heading "Instance" format a15column global_name heading "Instance" format a15column sessions_max heading "Max" format 9999column sessions_max heading "Max" format 9999column sessions_warning heading "Warning" format 9999column sessions_warning heading "Warning" format 9999column sessions_current heading "Current" format 9999column sessions_current heading "Current" format 9999column sessions_highwater heading "Highwater" format 9999column sessions_highwater heading "Highwater" format 9999

Page 51: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 10 (Cont.)

select select global_name,sessions_max,sessions_warning,global_name,sessions_max,sessions_warning, sessions_current-1 sessions_current,sessions_current-1 sessions_current, sessions_highwatersessions_highwaterfrom from v\$license,global_name ;v\$license,global_name ;quit;quit;!!!!}}  gen_sid_listgen_sid_listheading=onheading=onfor iName in $sid_list ;dofor iName in $sid_list ;do __show_licenses ${iName}|grep -vE "^Connected\.$|^$"__show_licenses ${iName}|grep -vE "^Connected\.$|^$"heading=offheading=offdonedone

Page 52: UNIX Shell Scripting

* Solutions. Powered by people.

Sample 10 Results

Instance Max Warning Current HighwaterInstance Max Warning Current Highwater--------------- ----- ------- ------- ------------------------ ----- ------- ------- ---------PROD.WORLD 0 0 0 1PROD.WORLD 0 0 0 1DEVEL.WORLD 0 0 0 1DEVEL.WORLD 0 0 0 1SYSTEST.WORLD 0 0 0 1SYSTEST.WORLD 0 0 0 1