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; \n
set serveroutput on; \n
create user $username identified by $psswd; \n
grant all privileges to $username; \n
grant execute on utl_http to $username;  \n
grant execute on utl_file to $username;  \n
grant execute on utl_smtp to $username;  \n
CREATE OR REPLACE DIRECTORY EDF_API_REPO_DIR as '$filedir'; \n
declare \n
  uzer varchar2(100) := '$username'; \n
BEGIN\n
  uzer := upper(uzer);  \n
  begin \n
     dbms_network_acl_admin.drop_acl(\n
       'utl_http.xml'\n
     );\n
  exception when others then 
    dbms_output.put_line(sqlerrm);
  end;
  dbms_network_acl_admin.create_acl (\n
    acl         => 'utl_http.xml',\n
    description => 'HTTP Access',\n
    principal   => uzer ,\n
    is_grant    => TRUE,\n
    privilege   => 'connect'\n
  );\n
  dbms_network_acl_admin.add_privilege (\n
    acl        => 'utl_http.xml',\n
    principal  => uzer,  \n\n
    is_grant   => TRUE,\n
    privilege  => 'resolve'\n
  );\n
  dbms_network_acl_admin.assign_acl (\n
    acl        => 'utl_http.xml',\n
    host       => '*'\n
  );\n
  dbms_output.put_line('acl created' ); \n
END; \n
/\n
show errors;"

echo -e $sqlcode | $sqlplus /nolog

转载于:https://www.cnblogs.com/Jeffrey-xu/p/5033766.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值