I have a ksh script that executes a program with a predetermined timeout in minutes. If the program takes longer then the timeout then it still completes with a return code of 0.
I would like to determine how long the program ran. Then if it takes longer than the timeout I would like to specify a new return code.
I tried to use the time command to display to the screen and log file. Then grab the real time from the output in the log file however I have had not success with redirecting the output to the log file.
Here is what I am trying to do. See how the output of time does not show up in the log.
$ time ls home test 2>&1 | tee -a test.log
ls: 0653-341 The file home does not exist.
test
real 0m0.01s
user 0m0.00s
sys 0m0.02s
$ cat test.log
ls: 0653-341 The file home does not exist.
test
There is another problem with this method as well. Depending on what system I run the program on it could take more than an hour to run. Then the real line would return something similar to this “real 4h15m0.23s”.
Does anyone have a good idea of what I could to determine how long my program is running? Or help me with what I have already started?