Debian Codegraph @

continue-n.example

raw
1 # Albert Reiner gives an example of how to use "continue N":
2 # ---------------------------------------------------------
3
4 # Suppose I have a large number of jobs that need to be run, with
5 #+ any data that is to be treated in files of a given name pattern
6 #+ in a directory. There are several machines that access
7 #+ this directory, and I want to distribute the work over these
8 #+ different boxen.
9 # Then I usually nohup something like the following on every box:
10
11 while true
12 do
13 for n in .iso.*
14 do
15 [ "$n" = ".iso.opts" ] && continue
16 beta=${n#.iso.}
17 [ -r .Iso.$beta ] && continue
18 [ -r .lock.$beta ] && sleep 10 && continue
19 lockfile -r0 .lock.$beta || continue
20 echo -n "$beta: " `date`
21 run-isotherm $beta
22 date
23 ls -alF .Iso.$beta
24 [ -r .Iso.$beta ] && rm -f .lock.$beta
25 continue 2
26 done
27 break
28 done
29
30 exit 0
31
32 # The details, in particular the sleep N, are particular to my
33 #+ application, but the general pattern is:
34
35 while true
36 do
37 for job in {pattern}
38 do
39 {job already done or running} && continue
40 {mark job as running, do job, mark job as done}
41 continue 2
42 done
43 break # Or something like `sleep 600' to avoid termination.
44 done
45
46 # This way the script will stop only when there are no more jobs to do
47 #+ (including jobs that were added during runtime). Through the use
48 #+ of appropriate lockfiles it can be run on several machines
49 #+ concurrently without duplication of calculations [which run a couple
50 #+ of hours in my case, so I really want to avoid this]. Also, as search
51 #+ always starts again from the beginning, one can encode priorities in
52 #+ the file names. Of course, one could also do this without `continue 2',
53 #+ but then one would have to actually check whether or not some job
54 #+ was done (so that we should immediately look for the next job) or not
55 #+ (in which case we terminate or sleep for a long time before checking
56 #+ for a new job).