
包含365个shell高级编程实例。
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
Shell脚本高级编程教程,旨在为您提供有益的指导。以下示例 10-23 阐述了在实际任务中利用 `continue N` 的应用:
1. 阿尔伯特·雷纳(Albert Reiner)提供了一个使用“continue N”的示例:
2. ---------------------------------------------------------
3. 假设我需要处理大量需要执行的任务,这些任务的数据存储在特定名称模式的文件中,这些文件位于一个指定的目录中。 多个机器同时访问这个目录,并且我希望将这些工作分配到不同的计算节点上。 因此,我通常会在每个节点上运行如下命令:
4. ```bash
while true
do
for n in .iso\.*
do
if [ $n = .iso.opts ]
then
continue
fi
beta=${n#.iso.}
if [ -r .Iso.$beta ]
then
continue
fi
if [ -r .lock.$beta ]
then
sleep 10 && continue
fi
lockfile -r0 .lock.$beta || continue
echo -n $beta: `date`
run-isotherm $beta
date
ls -alF .Iso.$beta
if [ -r .Iso.$beta ]
then
rm -f .lock.$beta
fi
continue 2
done
break 26 done # End of inner loop for processing files in directory.
done # End of outer loop for continuous job execution.
# The specific details, particularly the sleep duration, are tailored to my application; however, the fundamental pattern remains consistent:
5. ```bash
6. while true
7. do
8. for job in {pattern}
9. do
10. if {job already done or running}
11. then
12. continue 2 # Skip to the next job iteration if the current job is already in progress or completed.
13. fi # End of conditional check for existing jobs.
14. {mark job as running, do job, mark job as done} # Perform the necessary actions to execute the current job and update its status accordingly (e.g., start the process, execute the task). This section represents a placeholder for the actual job execution logic within this example script and should be replaced with appropriate commands or scripts to perform the desired tasks based on each `job`. This could involve executing another script, running a command-line tool, or performing any other action required by your specific use case.. Continue 2 # Skip to next iteration of outer loop after completing/skipping a particular Job..
15. continue 2 # Skip to next iteration of outer loop after processing a particular Job..
16. done # End of inner loop iterating through jobs based on defined pattern..
17. break # Exit from inner loop when all jobs are processed or no more jobs are available..
18.`sleep 600 to avoid termination.`# Optional sleep command added here for preventing premature script termination if no more jobs are available during runtime..
19.`done`# End of outer while loop that continues until no more jobs are available..
20.# This approach ensures that the script will only terminate when there are no remaining tasks to execute (including those added during runtime). Utilizing appropriate lockfiles enables concurrent execution across multiple machines without encountering duplication of calculations – a critical consideration given that my tasks can take several hours to complete, necessitating avoidance of redundant computations.. Furthermore, since searches always begin from the outset, priorities can be encoded within file names; alternatively, this functionality could be implemented without using `continue`, but it would necessitate explicit checks to determine whether a task was already completed before proceeding to search for subsequent tasks—potentially leading to either termination or prolonged waiting periods before checking for new jobs..
全部评论 (0)


