Ejemplos Shell PDF
Ejemplos Shell PDF
Oracle Professional
Jon Emmons
Oracle Consultant
Author
Scripting Basics
Troubleshooting
Some Scripts
Shell Scripting for the Oracle Professional Jon Emmons
When to Script
ORACLE_SID=oss
ps ef | grep $ORACLE_SID
ps ef | grep $ORACLE_SID
ps ef | grep $ORACLE_SID
ps ef | grep $ORACLE_SID
Note the variable being
used as an argument.
We'll see a lot of this.
echo "--- Load average numbers represent the 1, 5 and 15 minute load
averages ---"
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 add
here
#!/bin/sh
i=1
while [ $i -le 10 ]
do
echo "The current value of i is $i"
i=`expr $i + 1`
done
#!/bin/sh
count=0
for i in 2 4 6
do
echo "i is $i"
count=`expr $count + 1`
done
echo "The loop was executed $count times"
#!/bin/sh
files=`ls`
count=0
for i in $files
do
count=`expr $count + 1`
if [ $count -gt 100 ]
then
echo "There are more than 100 files in the current
directory"
break
fi
done
#!/bin/sh
echo "Enter your name"
read name
echo "Hi $name. I hope you like this script"
chmod u=rw,g=,o=
/u01/app/oracle/admin/oss/pw/system.pw
#!/bin/sh
lookup=$1
sqlplus -S system/manager << EOF
SELECT username, account_status,
expiry_date
FROM dba_users WHERE
lower(username)=lower('$lookup');
exit;
EOF
Shell Scripting for the Oracle Professional Jon Emmons
Getting Information Out of
SQL*Plus
The output of sqlplus can be sent to a file on the system
for further processing.
Output is redirected with the > symbol.
When redirecting both input and output things can get
confusing.
sqlplus -S "/ as sysdba" << EOF > $tempfile
set pagesize
select 'The following accounts were found to be unlocked and should not
be'
from dual;
define exit_status = 0
column xs new_value exit_status
select username, account_status, 1 as xs from dba_users
where account_status != 'LOCKED'
and username in ('HR', 'SCOTT', 'OUTLN', 'MDSYS', 'CTXSYS');
exit &exit_status
EOF
# If the exit status of sqlplus was not 0 then we will send an email
if [ $? != 0 ]
then
mail -s "Accounts Unlocked in $ORACLE_SID" oracle < $tempfile
fi
$ expr 2 + 7
9
$ expr 4 + 3 \* 3
13
$ expr 13 / 2
7
00 03 * * 0 /u01/app/oracle/admin/com
00 03 1-7 * 0
/u01/app/oracle/admin/com
Shell Scripting for the Oracle Professional Jon Emmons
Scheduling One-time Tasks with at
Use at for one-time tasks which need to be run
off-hours or at a specific time.
http://www.lifeaftercoffee.com/presentation-scripts/
Password: luwak
Burleson Consulting
Rampant TechPress