PROMPT Por Favor ingrese los siguientes Datos ( CTRL + C para cancelar ):
accept pathData char prompt '    Ubicaci�n datafiles de Datos   (LNX_DATA_?): ';
accept pathIndx char prompt '    Ubicaci�n datafiles de Indices (LNX_INDX_?): ';
accept passSys  char prompt '    Contrase�a usuario SYS : ';
accept passSystem  char prompt '    Contrase�a usuario SYSTEM : ';

PROMPT --> Creando Tablespace LNX_DATA_A en &pathData
 
CREATE TABLESPACE LNX_DATA_A
    LOGGING 
    DATAFILE '&pathData/lnx_data_a01.dbf' SIZE 200M
    AUTOEXTEND ON NEXT 20M
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL
    SEGMENT SPACE MANAGEMENT AUTO;

PROMPT --> Creando Tablespace LNX_DATA_D en &pathData

CREATE TABLESPACE LNX_DATA_D
    LOGGING 
    DATAFILE '&pathData/lnx_data_d01.dbf' SIZE 400M 
    AUTOEXTEND ON NEXT  20M 
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL
    SEGMENT SPACE MANAGEMENT AUTO;

PROMPT --> Creando Tablespace LNX_DATA_M en &pathData

CREATE TABLESPACE LNX_DATA_M
    LOGGING 
    DATAFILE '&pathData/lnx_data_m01.dbf' SIZE 400M
    AUTOEXTEND ON NEXT  20M
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT AUTO;

PROMPT --> Creando Tablespace LNX_INDX_A en &pathIndx

CREATE TABLESPACE LNX_INDX_A
    LOGGING 
    DATAFILE '&pathIndx/lnx_indx_a01.dbf' SIZE 200M
    AUTOEXTEND ON NEXT  20M 
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT AUTO;

PROMPT --> Creando Tablespace LNX_INDX_D en &pathIndx

CREATE TABLESPACE LNX_INDX_D
    LOGGING 
    DATAFILE '&pathIndx/lnx_indx_d01.dbf' SIZE 400M 
    AUTOEXTEND ON NEXT 20M 
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT AUTO;

PROMPT --> Creando Tablespace LNX_INDX_M en &pathIndx

CREATE TABLESPACE LNX_INDX_M
    LOGGING 
    DATAFILE '&pathIndx/lnx_indx_m01.dbf' SIZE 500M 
    AUTOEXTEND ON NEXT  20M
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT AUTO;

PROMPT --> Creando Tablespace LNX_USER en &pathData

CREATE TABLESPACE LNX_USER
    LOGGING
    DATAFILE '&pathData/lnx_user01.dbf' SIZE 300M
    AUTOEXTEND ON NEXT  20M 
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT AUTO;

PROMPT --> Creando Tablespace LNX_TEMP en &pathData

CREATE
    TEMPORARY TABLESPACE LNX_TEMP TEMPFILE
    '&pathData/lnx_temp01.dbf' SIZE 1500M
    AUTOEXTEND ON NEXT  20M
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL;

CREATE
    TEMPORARY TABLESPACE LNX_TEMP2 TEMPFILE
    '&pathIndx/lnx_temp02.dbf' SIZE 1500M
    AUTOEXTEND ON NEXT  20M
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL;

PROMPT --> Creando Tablespace LNX_ADT_DATA_A en &pathData

CREATE TABLESPACE LNX_ADT_DATA_A
    LOGGING 
    DATAFILE '&pathData/lnx_adt_data_a01.dbf' SIZE 5M
    AUTOEXTEND ON NEXT  20M 
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT  AUTO;

PROMPT --> Creando Tablespace LNX_ADT_DATA_D en &pathData

CREATE TABLESPACE LNX_ADT_DATA_D
    LOGGING 
    DATAFILE '&pathData/lnx_adt_data_d01.dbf' SIZE 500M
    AUTOEXTEND ON NEXT  20M 
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT AUTO;

PROMPT --> Creando Tablespace LNX_ADT_DATA_M en &pathData

CREATE TABLESPACE LNX_ADT_DATA_M
    LOGGING 
    DATAFILE '&pathData/lnx_adt_data_m01.dbf' SIZE 500M
    AUTOEXTEND ON NEXT  20M
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT  AUTO;

PROMPT --> Creando Tablespace LNX_ADT_INDX_A en &pathIndx

CREATE TABLESPACE LNX_ADT_INDX_A 
    LOGGING 
    DATAFILE '&pathIndx/lnx_adt_indx_a01.dbf' SIZE 5M
    AUTOEXTEND ON NEXT  20M 
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT  AUTO;

PROMPT --> Creando Tablespace LNX_ADT_INDX_D en &pathIndx

CREATE TABLESPACE LNX_ADT_INDX_D
    LOGGING 
    DATAFILE '&pathIndx/lnx_adt_indx_d01.dbf' SIZE 500M
    AUTOEXTEND ON NEXT  20M 
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT  AUTO;

PROMPT --> Creando Tablespace LNX_ADT_INDX_M en &pathIndx

CREATE TABLESPACE LNX_ADT_INDX_M
    LOGGING 
    DATAFILE '&pathIndx/lnx_adt_indx_m01.dbf' SIZE 5M
    AUTOEXTEND ON NEXT  20M 
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT  AUTO;

PROMPT --> Creando Tablespace LNX_ADT_USER en &pathData

CREATE TABLESPACE LNX_ADT_USER
    LOGGING 
    DATAFILE '&pathData/lnx_adt_user01.dbf' SIZE 50M
    AUTOEXTEND ON NEXT  20M 
    MAXSIZE UNLIMITED
    EXTENT MANAGEMENT LOCAL
   SEGMENT SPACE MANAGEMENT  AUTO;

PROMPT --> Creando Tablespace LNX_TRAME_LOB en &pathData

CREATE TABLESPACE LNX_TRAME_LOB
  DATAFILE '&pathData/lnx_trame_lob.dbf' SIZE 700M
  AUTOEXTEND ON NEXT 20M
  LOGGING
  ONLINE
  PERMANENT
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE
  BLOCKSIZE 8K
  SEGMENT SPACE MANAGEMENT AUTO
  FLASHBACK ON;

PROMPT --> Creando Tablespace LNX_TRAMN_LOB en &pathData

CREATE TABLESPACE LNX_TRAMN_LOB
  DATAFILE '&pathData/lnx_tramn_lob.dbf' SIZE 700M
  AUTOEXTEND ON NEXT 20M
  LOGGING
  ONLINE
  PERMANENT
  EXTENT MANAGEMENT LOCAL UNIFORM SIZE 3M
  BLOCKSIZE 8K
  SEGMENT SPACE MANAGEMENT AUTO
  FLASHBACK ON;

PROMPT --> Creando profile LINIX

CREATE PROFILE LINIX LIMIT
  SESSIONS_PER_USER UNLIMITED
  CPU_PER_SESSION UNLIMITED
  CPU_PER_CALL UNLIMITED
  CONNECT_TIME UNLIMITED
  IDLE_TIME UNLIMITED
  LOGICAL_READS_PER_SESSION UNLIMITED
  LOGICAL_READS_PER_CALL UNLIMITED
  COMPOSITE_LIMIT UNLIMITED
  PRIVATE_SGA UNLIMITED
  FAILED_LOGIN_ATTEMPTS 10
  PASSWORD_LIFE_TIME UNLIMITED
  PASSWORD_REUSE_TIME UNLIMITED
  PASSWORD_REUSE_MAX UNLIMITED
  PASSWORD_LOCK_TIME 1
  PASSWORD_GRACE_TIME 7
  PASSWORD_VERIFY_FUNCTION NULL;

PROMPT --> Creando Usuario LNXADT ( Clave LNXADT )

CREATE USER LNXADT  PROFILE LINIX 
    IDENTIFIED BY LNXADT DEFAULT TABLESPACE LNX_ADT_USER 
    TEMPORARY TABLESPACE LNX_TEMP 
    ACCOUNT UNLOCK;

GRANT CONNECT, DBA, SELECT ANY DICTIONARY TO LNXADT;

PROMPT --> Creando Usuario LINIX ( Clave LINIX )

CREATE USER LINIX PROFILE LINIX
    IDENTIFIED BY LINIX DEFAULT TABLESPACE LNX_USER
    TEMPORARY TABLESPACE LNX_TEMP2
    ACCOUNT UNLOCK;

GRANT CONNECT, DBA, SELECT ANY DICTIONARY, CREATE PUBLIC SYNONYM TO LINIX;

GRANT EXECUTE ON DBMS_LOCK TO LINIX;

GRANT ALL PRIVILEGES TO LINIX;

grant execute on sys.dbms_crypto to LINIX;

GRANT EXECUTE ON SYS.UTL_FILE TO LINIX;

PROMPT --> Creando rol LNXWEB

CREATE ROLE LNXWEB NOT IDENTIFIED;

PROMPT --> Creando Usuario WEB ( Clave WEB )

CREATE USER WEB PROFILE LINIX 
    IDENTIFIED BY WEB DEFAULT TABLESPACE LNX_USER 
    TEMPORARY TABLESPACE LNX_TEMP2 
    ACCOUNT UNLOCK;

GRANT CONNECT, LNXWEB TO WEB;

ALTER USER WEB DEFAULT ROLE LNXWEB;

PROMPT --> Creando Usuario COPIA ( Clave COPIA )

CREATE USER COPIA PROFILE LINIX IDENTIFIED BY COPIA;
--GRANT CONNECT, EXP_FULL_DATABASE, IMP_FULL_DATABASE, UNLIMITED TABLESPACE, DBA TO COPIA;
GRANT EXP_FULL_DATABASE, IMP_FULL_DATABASE, UNLIMITED TABLESPACE, CONNECT, FLASHBACK ANY TABLE TO COPIA;
grant EXEMPT ACCESS POLICY to COPIA;

PROMPT --> Creando Directorio Data_pump

CREATE OR REPLACE DIRECTORY DATA_PUMP_DIR_LINIX AS '/exp/linix';
GRANT READ, WRITE ON DIRECTORY DATA_PUMP_DIR_LINIX TO COPIA;

PROMPT --> Conectando como SYSDBA

CONNECT sys/&passSys as sysdba;

ALTER SYSTEM SET OPEN_CURSORS=19400 SCOPE=SPFILE;
ALTER SYSTEM SET UNDO_MANAGEMENT=AUTO SCOPE=SPFILE;
ALTER SYSTEM SET PROCESSES=900 SCOPE=SPFILE;
ALTER SYSTEM SET UTL_FILE_DIR=* SCOPE=SPFILE;

PROMPT --> Bajando Instancia 

SHUTDOWN IMMEDIATE;

PROMPT --> Generando archivo Init[Instancia].ora

CREATE PFILE FROM SPFILE;

PROMPT --> Subiendo la Instancia
STARTUP;

PROMPT --> Conectando como SYSTEM
CONNECT SYSTEM/&passSystem

PROMPT --> Creando ROL U_CONECTAR

CREATE ROLE "U_CONECTAR"  NOT IDENTIFIED;
GRANT CREATE SESSION TO "U_CONECTAR";
GRANT EXECUTE ANY PROCEDURE TO "U_CONECTAR";
GRANT SELECT ANY SEQUENCE TO "U_CONECTAR";
GRANT SELECT ANY TABLE TO "U_CONECTAR";

PROMPT --> Creando ROL U_FINAL

CREATE ROLE "U_FINAL"  NOT IDENTIFIED;
GRANT CREATE SESSION TO "U_FINAL";
GRANT EXECUTE ANY PROCEDURE TO "U_FINAL";
GRANT SELECT ANY SEQUENCE TO "U_FINAL";
GRANT SELECT ANY TABLE TO "U_FINAL";
GRANT INSERT ANY TABLE TO "U_FINAL";
GRANT DELETE ANY TABLE TO "U_FINAL";
GRANT UPDATE ANY TABLE TO "U_FINAL";
GRANT ALTER USER TO "U_FINAL";
GRANT ALTER SESSION TO "U_FINAL";
