打开支付宝首页搜“523966799”领红包,领到大红包的小伙伴赶紧使用哦!

 找回密码
 立即注册

QQ登录

只需一步,快速开始

通过shell脚本随机插入sql语句

2021-8-16 19:39| 发布者: zhaojun917| 查看: 1661| 评论: 0

摘要: EOF要在第一位,前面不能空格
前期工作:创建表与序列。以及注释
后期工作:个人借用了crontab来进行定时任务的触发随机脚本
create table TB_SERVICE_MONITOR
(
  id          NUMBER,
  server_name VARCHAR2(20),
  time        VARCHAR2(30)
)

comment on column TB_SERVICE_MONITOR.id
  is 'ID';
comment on column TB_SERVICE_MONITOR.server_name
  is '应用名称';
comment on column TB_SERVICE_MONITOR.time
  is '访问时间';

create sequence SERVER_MONI_SEQ
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;


#! /bin/bash

##--插入的sql,   'bszn'为server_name名称

source .bash_profile  
    --引入oracle的环境变量,否则脚本在crontab中执行时会报错,但手动执行却是正常的,故需要添加
declare -i rnum=$RANDOM*8/32767 
    --declare -i 声明一个整数数值类型,rnum为变量。在32767为在0-32767中间随机生成一个数值(确定了一个大的取值范围,个人理解),$RANDOM为随机函数,*8为在0-7之间随机产生数值(从大的范围中,再一次缩小范围)。

if [ "$rnum" -eq "1" ];then    --数值之间的比较用英文字母的eq,lt等,字符串用=,!=之类的
    /oracle/product/10g/bin/sqlplus hr/hr1234@192.168.4.22:1521/orcl@192.168.4.22:1521/orcl 1>sql.log 2>&1 <           --sqlplus的远程登录方式,以及sqlplus在oracle服务器中的绝对路径,可以通过find /$oracle_home -name sqlplus查得
    insert into tb_service_monitor values(SERVER_MONI_SEQ.nextval,'bszn',to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'));
    commit;
    exit;
EOF  --此处必须顶头写,否则linux shell认为没有EOF结束标签,只有<     else
    if [ "$rnum" -eq "2" ];then
    /oracle/product/10g/bin/sqlplus hr/hr1234@192.168.4.22:1521/orcl 1>sql.log 2>&1 <     insert into tb_service_monitor  values(SERVER_MONI_SEQ.nextval,'tqyb',to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'))
    commit;
    exit;
EOF
    else
    if [ "$rnum" -eq "3" ];then
    /oracle/product/10g/bin/sqlplus hr/hr1234@192.168.4.22:1521/orcl 1>sql.log 2>&1 <     insert into tb_service_monitor  values(SERVER_MONI_SEQ.nextval,'wdzb',to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'));
    commit;
    exit;
EOF
    else
    if [ "$rnum" -eq "4" ];then
    /oracle/product/10g/bin/sqlplus hr/hr1234@192.168.4.22:1521/orcl 1>sql.log 2>&1 <     insert into tb_service_monitor  values(SERVER_MONI_SEQ.nextval,'gsgg',to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'));
    commit;
    exit;
EOF

    else
    if [ "$rnum" -eq "5" ];then
    /oracle/product/10g/bin/sqlplus hr/hr1234@192.168.4.22:1521/orcl 1>sql.log 2>&1 <     insert into tb_service_monitor  values(SERVER_MONI_SEQ.nextval,'cydh',to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'));
    commit;
    exit;
EOF
    
    else
    if [ "$rnum" -eq "6" ];then
    /oracle/product/10g/bin/sqlplus hr/hr1234@192.168.4.22:1521/orcl 1>sql.log 2>&1 <     insert into tb_service_monitor  values(SERVER_MONI_SEQ.nextval,'cxgjj',to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'));
    commit;
    exit;
EOF
    else
    if [ "$rnum" -eq "7" ];then
    /oracle/product/10g/bin/sqlplus hr/hr1234@192.168.4.22:1521/orcl 1>sql.log 2>&1 <     insert into tb_service_monitor  values(SERVER_MONI_SEQ.nextval,'fdjs',to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'));
    commit;
    exit;
EOF
    fi
    fi
    fi
    fi
    fi
    fi
fi
关闭

站长推荐上一条 /7 下一条

QQ|手机版|小黑屋|梦想之都-俊月星空 ( 粤ICP备18056059号 )

GMT+8, 2024-9-20 02:34 , Processed in 0.021639 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

返回顶部