bash – shell脚本:并行运行一批N个命令,等待全部完成,然后运行
发布时间:2020-12-15 18:34:54 所属栏目:安全 来源:网络整理
导读:任务:运行由3-5个命令组成的块(并行/后台). 示例块: dd if=/dev/urandom of=/mnt/1/x bs=1024 count=1024000000 dd if=/dev/urandom of=/mnt/2/x bs=1024 count=1024000000 dd if=/dev/urandom of=/mnt/3/x bs=1024 count=1024000000 完成后,下一个块应该
任务:运行由3-5个命令组成的块(并行/后台).
示例块: dd if=/dev/urandom of=/mnt/1/x bs=1024 count=1024000000 & dd if=/dev/urandom of=/mnt/2/x bs=1024 count=1024000000 & dd if=/dev/urandom of=/mnt/3/x bs=1024 count=1024000000 & 完成后,下一个块应该运行. task1.sh: real_task1 real_param1 ; rm /var/lock/myscript/task1.lock task2.sh: real_task2 real_param1 ; rm /var/lock/myscript/task2.lock … taskgen.sh: # loop # while directory isn't empty - wait... gen_tasks.pl # build task files from some queue for i in 1 2 3; do touch /var/lock/myscript/task$i.lock ; done ./task1.sh & ./task2.sh & ./task3.sh & # if task1.sh doesn't exits then exit,else loop waits for files to be deleted 检查目录是否为空的一些方法可以找到here,不确定使用哪个; 问题:有没有更好的方法来实现这个? 附:可能的状态报告方法: command && report_good_state.sh taskid ; report_state_done.sh taskid; rm /var/lock/myscript/taskN.lock
这正是070??00的设计目标,因此我强烈建议您使用它.特别是,看看它运行它
as a semaphore:
for i in {1..4} do echo running $i sem -j3 df dd if=/dev/urandom of=/mnt/$i/x bs=1024 count=1024000000 ";" echo done done # sem --wait waits until all jobs are done. sem --wait (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 角度4 AOT与webpack
- 在Scala中尝试Haskell样式的惰性求值时出现堆栈溢出错误
- scala – Array类型的奇怪行为
- Rally REST webservice API入门
- General Object Initiating Function by the Example of $i
- 用于替换字符串中的文件扩展名的Scala表达式
- twitter-bootstrap-3 – Bootstrap DatePicker setDate方法
- scala – 如何在Play Framework的路由文件中使用导入和隐含
- vim – 在选择垂直块之后如何粘贴光标?
- 使用docker安装tar时,设备上没有剩余空间