I have written a large script to run a series of tests. Each test is a function on its own and I call these functions serially to get the job done.
I now want to make provisions to resume script run from the last function where it was aborted (e.g. in case system hangs). The logic I am using now is to write progress status into a file and then check the file content to determine where to start the script and resume from there.
However, I can’t continue using this logic because I want to introduce a menu into the script where I want to be able to choose from:
1) Run all tests from beginning to end
2) Run individual tests (brings up another menu with individual test options)
3) Resume from last abort
I have the written the code for the menu but still haven’t figured out how to fit my existing logic with the case construct used in my menu system. I am unhappy with the current resume from last abort logic I am using presently, which is:
fn1()
{
#do a bunch of things
echo 1 > progress.log
fn2
}
fn2()
{
STATUS=`cat progress.log`
case "$STATUS" in
1)
#do a bunch of things
echo 2 > progress.log
fn3
;;
*)
fn3
;;
esac
}
..
..
# and more functions in the same style as fn2
..
# main call
if [ -f progress.log ]
fn2
else
fn1
fi
Any ideas for a cleaner way to do this resume logic while integrating it with the ability to run tests individually when required? Thanks.
How about something like this. Drop the logic in fn1..N that link them together, but still write the
progress.logfile in there, and then do this:EDIT: with this version, you can just replace fn1, fn2, etc with the test names, so that you still get a runtest N interface that you can use to tie it all together.