grant execute on dbms_lock to ijx130355;
--建立两个测试过程
source ~/.bash_profile
sqlplus xxx/xxx <<EOF
execute proc_test1;
execute proc_test2;
EOF
[oracle@scard yhaichao]$ crontab -l
30 16 * * * /home/oracle/yhaichao /proc_test.sh
IJX130355@scard>select * from test; --查看结果
INDATE PROC_NAME
------------------- ------------------------------
2014-07-09 16:30:01 proc_test1
2014-07-09 16:31:01 proc_test1
2014-07-09 16:31:01 proc_test2
2014-07-09 16:32:01 proc_test2
IJX130355@scard>
结论: cron执行sh脚本是按照前后顺序执行的,前边的过程执行完才会执行下一个过程!!
source ~/.bash_profile
sqlplus xxx/xxx <<EOF
execute proc_test1;
EOF
[oracle@scard ~]$ tail proc_test2.sh
source ~/.bash_profile
sqlplus xxx/xxx <<EOF
execute proc_test2;
38 16 * * * /home/oracle/yhaichao/ proc_test1.sh
38 16 * * * /home/oracle/yhaichao/ proc_test2.sh
IJX130355@scard>select * from test; --查看最后结果
INDATE PROC_NAME
------------------- ------------------------------
2014-07-09 16:38:01 proc_test2
2014-07-09 16:39:01 proc_test2
2014-07-09 16:38:01 proc_test1
2014-07-09 16:39:01 proc_test1
--建立两个测试过程
create or replace procedure proc_test1 as
begin
insert into test values(sysdate,'proc_test1');
DBMS_LOCK.SLEEP(60);
insert into test values(sysdate,'proc_test1');
commit;
end;
create or replace procedure proc_test2 as
begin
insert into test values(sysdate,'proc_test2');
DBMS_LOCK.SLEEP(60);
insert into test values(sysdate,'proc_test2');
commit;
end;
--------------------------------------------------------
方案1: 两个过程在同一个cron中执行
[oracle@scard ~]$ tail proc_test.shsource ~/.bash_profile
sqlplus xxx/xxx <<EOF
execute proc_test1;
execute proc_test2;
EOF
[oracle@scard yhaichao]$ crontab -l
30 16 * * * /home/oracle/yhaichao /proc_test.sh
IJX130355@scard>select * from test; --查看结果
INDATE PROC_NAME
------------------- ------------------------------
2014-07-09 16:30:01 proc_test1
2014-07-09 16:31:01 proc_test1
2014-07-09 16:31:01 proc_test2
2014-07-09 16:32:01 proc_test2
IJX130355@scard>
结论: cron执行sh脚本是按照前后顺序执行的,前边的过程执行完才会执行下一个过程!!
方案2: 将过程分别放到两个cron中
source ~/.bash_profile
sqlplus xxx/xxx <<EOF
execute proc_test1;
EOF
[oracle@scard ~]$ tail proc_test2.sh
source ~/.bash_profile
sqlplus xxx/xxx <<EOF
execute proc_test2;
EOF
IJX130355@scard>truncate table test; --将之前数据清理
38 16 * * * /home/oracle/yhaichao/ proc_test1.sh
38 16 * * * /home/oracle/yhaichao/ proc_test2.sh
IJX130355@scard>select * from test; --查看最后结果
INDATE PROC_NAME
------------------- ------------------------------
2014-07-09 16:38:01 proc_test2
2014-07-09 16:39:01 proc_test2
2014-07-09 16:38:01 proc_test1
2014-07-09 16:39:01 proc_test1
IJX130355@scard>
结论:可以看到将过程分开放到两个cron 中,os 会在同一时间执行两个过程!!