1- #!/bin/ksh operating system and shell type may cause different behaviour, this script is written and tested for Solaris and Korn Shell 2- if [ $# != 7 ] .. Control for wrong argument count passed to the script from shell. 3- export CIGDEM_USERNAME1=$1 .. export OH10=some-value .. assign each argument into variables which will be used inside shell and sqlplus commands. Here $1 shows first parameter passed from shell to the script. 4- $OH10/bin/sqlplus -s > $CIGDEM_LOG_DIR/step1_$CIGDEM_DATE.log 2> $CIGDEM_LOG_DIR/step1_$CIGDEM_DATE.err < and 2> options to redirect the outputs into files which may be needed for troubleshooting. c. $CIGDEM_USERNAME1/$CIGDEM_PASSWORD1@$OTNS10 connecting this way lets you hide the password from the other os users, ps command only shows sqlplus. d. @$CIGDEM_DIR/step1.sql $CIGDEM_EXP_DIR $CIGDEM_USERNAME3 $CIGDEM_PASSWORD3 $PERMANANT_TABLESPACE $TEMPORARY_TABLESPACE here we call step1.sql with arguments, they will be used with &n symbol inside sql statement. 5- inside the step1.sql; .. CREATE USER &2 IDENTIFIED by &3 TEMPORARY TABLESPACE &5 DEFAULT TABLESPACE &4 ; .. here nothing new, just the arguments passed are used with & symbol. 6- retc=$? if [[ $retc = 0 ]] to check if the last shell operation failed or not. if failed application exits. 7- $OH9/bin/exp $CIGDEM_USERNAME2 .. typical export step, some performance options like direct and buffers are set, and since there is a potential to call this script from unix cron any path is also given in front of the binary called. 8- inside the step4.sql; .. SET HEADING OFF ECHO OFF FEEDBACK OFF .. .. spool &1/step4_&2 SELECT ... spool off ... this is the way to produce dynamic runnable sql scripts from Oracle dictionary, you spool the output and then you execute it. 9- inside the step4.sql; .. VARIABLE vgrantor varchar2(20); BEGIN SELECT upper(to_char('&3')) INTO :vgrantor FROM DUAL; dbms_output.put_line(:vgrantor); END; / .. SELECT 'revoke ' || privilege || ' on ' || table_name || ' from ' || grantee || ' ;' FROM user_tab_privs p WHERE p.privilege NOT IN ('SELECT') AND p.grantor = :vgrantor ; .. here we create a host variable from one argument passed from shell in order to use it in the where clause. --- here is the output of the test I have done and the os/db informations; SP2D test@ctibcp:/export/home/test/cido # ls clone_user.ksh exp log step1.sql step4.sql SP2D test@ctibcp:/export/home/test/cido # ./clone_user.ksh osas_tyilmaz x adrref y adrref z 29112007 ** User Drop OK ... ** 11/30/07 08:37:27 ** Export OK ... ** 11/30/07 08:37:30 ** Import OK ... ** 11/30/07 08:37:48 ** Revoke Script OK ... ** 11/30/07 08:37:50 ** Revoke OK ... ** 11/30/07 08:37:50 SP2D test@ctibcp:/export/home/test/cido # uname -a SunOS ctibcp 5.10 Generic_125100-10 sun4u sparc SUNW,Sun-Fire-V890 SP2D test@ctibcp:/export/home/test/cido # sqlplus /nolog SQL*Plus: Release 10.2.0.2.0 - Production on Thu Nov 29 17:03:45 2007 Copyright (c) 1982, 2005, Oracle. All Rights Reserved. SQL>