rshellsweave

Timed exit from a shell command


I have a shell script to generate two types of reports. Each report is generated by executing a Sweave script and then compiling a PDF out of the resulting tex file.

eval "R CMD Sweave Weekly.Rnw"
eval "pdflatex Weekly.tex"
eval "R CMD Sweave Daily.Rnw"
eval "pdflatex Daily.tex"

For instance, if there is an error when executing 'R CMD Sweave Weekly.Rnw', it exits but still generates a tex file (which I have checked cannot be stopped) and this tex file would not compile correctly in pdflatex i.e. 'pdflatex Weekly.tex' command would hang and the shell script will not move to the next 'R CMD Sweave Daily.Rnw'.

Now, my question: If I know that a certain shell command should not take more 30 secs, is there a way to induce a timed exit from that command (assuming it hung) after say a couple minutes (or some arbitrary time lapse)? Alternatively, is there a way to force shutdown a latex engine after it encounters errors when compiling a tex file?


Solution

  • Use pdflatex -halt-on-error to stop pdflatex from asking questions.