zoukankan      html  css  js  c++  java
  • A simple and practical shell script

       There is a very useful shell script to handle something for utl_file, utl_http and utl_smtp. The following code will create a directory for using utl_file to operate file and grant execute on utl_file to useraccount you have created, we should log in oracle by user sys at first. About utl_http and utl_smtp, it will do the same as the above. Also, if we want to use the function of utl_file in normal, we should set the related configuration in acl(access control list). Maybe you have noticed the end of below code, it will make some configuration for acl. Use this script, you're gonna be more efficient during your work.

    #!/bin/bash
    sqlplus=sqlplus64
    username=$1
    psswd=$2
    filedir=$3
    [[ $filedir ]] || filedir="/sandbox/EDF_API_REPO_DIR"
    [[ -d $filedir ]] || { echo "mkdir $filedir"; mkdir $filedir; chmod 777 $filedir; }
    [[ -d $filedir ]] || { echo "cannot create oracle directory"; exit 1; }   
    [[ $username ]] || { echo "Where is user name?" ; exit 1; } 
    [[ $psswd ]] || psswd=$username 
    echo "create user $username identified by $psswd"; 
    sqlcode="
    connect sys/111111@localhost:1522/xe as sysdba; 
    
    set serveroutput on; 
    
    create user $username identified by $psswd; 
    
    grant all privileges to $username; 
    
    grant execute on utl_http to $username;  
    
    grant execute on utl_file to $username;  
    
    grant execute on utl_smtp to $username;  
    
    CREATE OR REPLACE DIRECTORY EDF_API_REPO_DIR as '$filedir'; 
    
    declare 
    
      uzer varchar2(100) := '$username'; 
    
    BEGIN
    
      uzer := upper(uzer);  
    
      begin 
    
         dbms_network_acl_admin.drop_acl(
    
           'utl_http.xml'
    
         );
    
      exception when others then 
        dbms_output.put_line(sqlerrm);
      end;
      dbms_network_acl_admin.create_acl (
    
        acl         => 'utl_http.xml',
    
        description => 'HTTP Access',
    
        principal   => uzer ,
    
        is_grant    => TRUE,
    
        privilege   => 'connect'
    
      );
    
      dbms_network_acl_admin.add_privilege (
    
        acl        => 'utl_http.xml',
    
        principal  => uzer,  
    
    
        is_grant   => TRUE,
    
        privilege  => 'resolve'
    
      );
    
      dbms_network_acl_admin.assign_acl (
    
        acl        => 'utl_http.xml',
    
        host       => '*'
    
      );
    
      dbms_output.put_line('acl created' ); 
    
    END; 
    
    /
    
    show errors;"
    
    echo -e $sqlcode | $sqlplus /nolog

  • 相关阅读:
    java 内存命令
    sts4 集成 springboot 和 activiti5
    sts4 安装spring xml 的提示。
    去除office 2019 由于您的登录凭据已经过期,的提示。
    「なきゃ」和「なくちゃ」分别是什么的原型?
    能力考必看|推荐三本适合N1和N2能力考练听力的书|帝京日语
    影子练习
    早大前辈分享日本留学生考试(EJU)日语高分经验
    星野源 新垣结衣 结婚
    使Nginx支持更多并发 请求的 Linux内核参数的优化
  • 原文地址:https://www.cnblogs.com/Jeffrey-xu/p/5033766.html
Copyright © 2011-2022 走看看