I've got a shell script doing connection performance test, that I timeout if it takes too long.
Upon timeout, it logs the results of a few commands so I can make myself an idea of the system status at the time of failure. I would like to run some commands depending on which phase of the test it timed-out.
I came up with the following script:
#!/bin/bash
TESTCASE="INITIAL"
function testing()
{
let TESTCASE="FIRST"
#do some testing
let TESTCASE="SECOND"
#do some testing
let TESTCASE="THIRD"
#do some testing
}
function logonerror(){
if [ "$TESTCASE" = "FIRST" ]; then
#logging command relevant to first test case
elif [ "$TESTCASE" = "SECOND" ]; then
#logging command relevant to second test case
elif [ "$TESTCASE" = "THIRD" ]; then
#logging command relevant to third test case
fi
#some additional standard logging
}
timeout 7200 cat <( testing )
if (($? == 124)); then
logonerror
fi
cleanup
The only issue I have is that it doesn't matter which phase it timed-out, when doing the logging it always think it is at the initial phase.
How can I make sure that the test phase information get correctly updated?