请教Linux shell下如何同时执行多个脚本

geigers 2008-06-11 09:33:19
是这样的,我这里有一个需要在后台做的批量业务(一次性的),每次的脚本数量比较大,要求最好能同时开始执行。顺序执行的我已经能实现了,但是,同时执行(或者每隔一秒自动打开下一个脚本,而不管上一个脚本是否执行完也行)一直不知道怎么处理,请各位大侠指点一下。
...全文
2741 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
geigers 2008-06-12
  • 打赏
  • 举报
回复
我写了个测试的例子,但是还没有运行出来结果,所以上来再问问,看能不能得到结果。呵呵。
geigers 2008-06-12
  • 打赏
  • 举报
回复
sqlplus test/test @/home/oracle/test >/home/oracle/test/out1.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out2.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out3.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out4.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out5.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out6.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out7.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out8.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out9.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out10.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out11.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out12.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out13.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out14.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out15.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out16.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out17.command 2>&1 &
sqlplus test/test @/home/oracle/test >/home/oracle/test/out18.command 2>&1 &



直接了当的说吧,呵呵,我要执行的是诸如以上的脚本,进行数据库后台操作,就像上面的命令,我如果直接贴到终端窗口里面,怎么知道是并行执行还是串行执行呢?


谢谢dxing_1983 呵呵,不过,好复杂,看不懂。

如果能明确是后台并行执行,那么使用&就足够了。
威廉-丁 2008-06-12
  • 打赏
  • 举报
回复
关注
lbaby 2008-06-12
  • 打赏
  • 举报
回复
stop 说明你的程序在后台时想读取stdin


你可以试试 cat &
是一样的道理


sqlplus user/passwd@mydb<<eof
select sysdate from dual;
eof

上边的代码就没有问题
lbaby 2008-06-12
  • 打赏
  • 举报
回复

可以参考下边的并行解压脚本,
下边的脚本会同时开20个解压缩进程,在解压大批量(1万以上)的文件时,速度很快(在超过24路的SMP机器上)
for f in *gz
do
gzip -d $f &
n=`ps | wc -l`
while [ $n -gt 20 ]
do
n=`ps | wc -l`
sleep 1
done
done
geigers 2008-06-12
  • 打赏
  • 举报
回复
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out1.command 2>&1 &
[55] 557
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out2.command 2>&1 &
[56] 558
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out3.command 2>&1 &
[57] 559
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out4.command 2>&1 &
[58] 561
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out5.command 2>&1 &
[59] 562
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out6.command 2>&1 &
[60] 563
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out7.command 2>&1 &
[61] 564
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out8.command 2>&1 &
[62] 565

[55] Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out1.command 2>&1

[56] Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out2.command 2>&1

[58]+ Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out4.command 2>&1
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out9.command 2>&1 &
[63] 572
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out10.command 2>&1 &
[64] 573
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out11.command 2>&1 &
[65] 574

[59]+ Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out5.command 2>&1
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out12.command 2>&1 &
[66] 579

[57] Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out3.command 2>&1

[60] Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out6.command 2>&1

[61]+ Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out7.command 2>&1
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out13.command 2>&1 &
[67] 580
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out14.command 2>&1 &
[68] 581
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out15.command 2>&1 &
[69] 584

[63] Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out9.command 2>&1

[64]+ Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out10.command 2>&1
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out16.command 2>&1 &
[70] 585
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out17.command 2>&1 &
[71] 586
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >/home/oracle/test/out18.command 2>&1 &
[72] 587

[62] Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out8.command 2>&1

[65]- Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out11.command 2>&1

[66]+ Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out12.command 2>&1
[oracle@xxzx ~]$
[oracle@xxzx ~]$
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test1.command 2>&1 &
[73] 595

[67]+ Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out13.command 2>&1

[68] Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out14.command 2>&1

[69] Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out15.command 2>&1

[70] Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out16.command 2>&1

[71] Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out17.command 2>&1

[72]- Stopped sqlplus test/test @/home/oracle/test >/home/oracle/test/out18.command 2>&1
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test2.command 2>&1 &
[74] 596
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test3.command 2>&1 &
[75] 597
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test4.command 2>&1 &
[76] 601
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test5.command 2>&1 &
[77] 602
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test6.command 2>&1 &
[78] 603
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test7.command 2>&1 &
[79] 604

[75]+ Stopped sqlplus test/test @/home/oracle/test >test3.command 2>&1
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test8.command 2>&1 &
[80] 608

[73]+ Stopped sqlplus test/test @/home/oracle/test >test1.command 2>&1
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test9.command 2>&1 &
[81] 609
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test10.command 2>&1 &
[82] 610
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test11.command 2>&1 &
[83] 611

[74] Stopped sqlplus test/test @/home/oracle/test >test2.command 2>&1

[76] Stopped sqlplus test/test @/home/oracle/test >test4.command 2>&1

[77] Stopped sqlplus test/test @/home/oracle/test >test5.command 2>&1

[78] Stopped sqlplus test/test @/home/oracle/test >test6.command 2>&1

[79]+ Stopped sqlplus test/test @/home/oracle/test >test7.command 2>&1
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test12.command 2>&1 &
[84] 617
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test13.command 2>&1 &
[85] 618
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test14.command 2>&1 &
[86] 619
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test15.command 2>&1 &
[87] 620
[oracle@xxzx ~]$ sqlplus tet/test @/home/oracle/test >test16.command 2>&1 &
[88] 622

[80]- Stopped sqlplus test/test @/home/oracle/test >test8.command 2>&1

[81]+ Stopped sqlplus test/test @/home/oracle/test >test9.command 2>&1
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test17.command 2>&1 &
[89] 623
[oracle@xxzx ~]$ sqlplus test/test @/home/oracle/test >test18.command 2>&1 &
[90] 624
[oracle@xxzx ~]$
[oracle@xxzx ~]$
[oracle@xxzx ~]$

[82] Stopped sqlplus test/test @/home/oracle/test >test10.command 2>&1

[83] Stopped sqlplus test/test @/home/oracle/test >test11.command 2>&1

[84] Stopped sqlplus test/test @/home/oracle/test >test12.command 2>&1

[85] Stopped sqlplus test/test @/home/oracle/test >test13.command 2>&1

[86] Stopped sqlplus test/test @/home/oracle/test >test14.command 2>&1

[87] Stopped sqlplus test/test @/home/oracle/test >test15.command 2>&1

[88]- Stopped sqlplus test/test @/home/oracle/test >test16.command 2>&1

[89]+ Stopped sqlplus test/test @/home/oracle/test >test17.command 2>&1

[90] Stopped sqlplus test/test @/home/oracle/test >test18.command 2>&1
[oracle@xxzx ~]$


上面是我执行的结果,从数据库的查询来看,没有什么纪录,诸位,谁知道上面的stop是什么意思呢?

另外,把上面用sqlplus执行的PL/SQL程序贴出来,也算个参考:

DECLARE
I INTEGER := 0;
C INTEGER;
BEGIN
SELECT COUNT(*) INTO C FROM TESTTABLE005;
INSERT INTO TESTTABLE005 T005 (C01, C02) VALUES (SYSDATE, C);
COMMIT;
LOOP
INSERT INTO TESTTABLE005 T005 (C01, C02, C03) VALUES (SYSDATE, C, I);
I := I + 1;
EXIT WHEN I = 50;
END LOOP;
COMMIT;
END;
EXIT
geigers 2008-06-11
  • 打赏
  • 举报
回复
诸位,俺是刚学的,是Oracle数据库上用的脚本,服务器是rh as 4 update 4。
能不能详细一些,呵呵,俺有些不大明白。
crotab这个我知道,但是,总共有2500个以上的脚本(事务控制要求的),全部是一次性调用,不过是分批去做,一次在4节点RAC的Oracle上跑,一批大概500个左右。有些脚本运行出问题后还要重新执行,所以,感觉涌crotab不是很理想,最好是一个脚本,运行后开始同时多进程执行这些。
至于&,呵呵,小弟我正在学习,谢谢了先,问题解决了坚决回帖。
cceczjxy 2008-06-11
  • 打赏
  • 举报
回复
如楼上,后台提交,或则用crotab定时提交。
过客猫2022 2008-06-11
  • 打赏
  • 举报
回复
楼主可以写一个脚本,让这些脚本全部后台运算,正楼上兄弟说的就可以了。
joan8363 2008-06-11
  • 打赏
  • 举报
回复
用& 都在后台跑就行了啊
dxing_1983 2008-06-11
  • 打赏
  • 举报
回复
http://www.9php.com/FAQ/cxsjl/c/2008/02/5381047111585.html

23,118

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧