My program takes two variables (n & k, from 1 to 100).
PROGRAM n k INPUT > OUTPUT
I want to find out which combination of variables gives the best output. This is my way of doing this:
for n in {1..100}; do
for k in {1..100}; do
PROGRAM n k INPUT |
awk -v n="$n" -v k="$k" '{print n,k,$0}' >> OUTPUT # Latter I analyse output and select best combination
done
done
This works perfectly. However some variables (e.g, n from 80 to 90) takes really long time to run.
What I want:
Run given script for a specific amount of time and if PROGRAM hasn't finished jump to the following variable.
For example:
(n=11; k=23) PROGRAM 11 23 INPUT # Runs 59 seconds -- OK
(n=11; k=24) PROGRAM 11 24 INPUT # Runs 34 seconds -- OK
(n=11; k=25) PROGRAM 11 25 INPUT # Already runs 60 seconds -- Too much. End and jump to (n=11; k=26)
(n=11; k=26) PROGRAM 11 26 INPUT