You could use the -file-line-error option and then grep the output for something of that form filename:##:error code (Below I just use the regex .*:[0-9]*:.*. Works decently well on a few tests.
Note, bibtex is run on the .aux file not the .tex file. For it, using the -terse option is probably sufficient.
Lastly I have no idea what your module load ctan does (--I have no such program--), so I excluded it.
#!/bin/bash
ARGUMENT="$1"
#determine aux name by stripping .tex suffix and adding .aux
AUXNAME="${ARGUMENT%.tex}.aux"
pdflatex -shell-escape -interaction=nonstopmode -file-line-error "$ARGUMENT" | grep ".*:[0-9]*:.*"
bibtex -terse "$AUXNAME"
pdflatex -shell-escape -interaction=nonstopmode -file-line-error "$ARGUMENT" | grep ".*:[0-9]*:.*"
You might want to play around with the -A and -B options to grep if you want some context surrounding the error messages, rather than just a single line.
I'd also play around with using if constructs or checking exit status to determine whether the last two steps should be done. (E.g., if an error is found in the first run, don't bother with the second, etc.) I can give more details if need be.
EDIT: Just saw your comment about warnings. The above will only catch true errors. I'm not sure there is a standard to warning messages, but grepping for the word "warning" might be good enough. so then it's something like:
#!/bin/bash
ARGUMENT="$1"
#determine aux name by stripping .tex suffix and adding .aux
AUXNAME="${ARGUMENT%.tex}.aux"
pdflatex -shell-escape -interaction=nonstopmode -file-line-error "$ARGUMENT" | grep -i ".*:[0-9]*:.*\|warning"
bibtex -terse "$AUXNAME"
pdflatex -shell-escape -interaction=nonstopmode -file-line-error "$ARGUMENT" | grep -i ".*:[0-9]*:.*\|warning"
-halt-on-errorflag, which stops on first error. Also two LaTeX passes may not be enough in general. And what about warning messages? – Andrey Vihrov Sep 08 '11 at 16:52stdoutandstderr. – egreg Sep 08 '11 at 17:03