前期工作:创建表与序列。以及注释
后期工作:个人借用了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
阅读(3131) | 评论(1) | 转发(1) |