Skip to content

Commit 1ebbf19

Browse files
Built-in template: make bash template redirect all stdout and stderr to the batchtools log file
1 parent accebeb commit 1ebbf19

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

inst/templates/bash.tmpl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ set -u # error on unset variables
1111
set -o pipefail # fail a pipeline if any command fails
1212
trap 'echo "ERROR: future.batchtools job script failed on line $LINENO" >&2; exit 1' ERR
1313

14+
## Redirect stdout and stderr to the batchtools log file
15+
exec > <%= log.file %> 2>&1
16+
1417
<%
1518
## Maximum runtime?
1619
runtime <- resources[["timeout"]]
@@ -33,17 +36,25 @@ trap 'echo "ERROR: future.batchtools job script failed on line $LINENO" >&2; exi
3336
writeLines(startup)
3437
} %>
3538

36-
echo "Load environment modules:"
3739
<% if (length(modules) > 0) {
38-
writeLines(c(sprintf("module load %s", modules), "module list"))
40+
writeLines(c(
41+
'echo "Load environment modules:"',
42+
sprintf('echo "- modules: %s"', paste(modules, collapse = ", ")),
43+
sprintf("module load %s", paste(modules, collapse = " ")),
44+
"module list"
45+
))
3946
} %>
4047

4148
# Launch R and evaluate the batchtools R job
42-
echo "Command: Rscript -e 'batchtools::doJobCollection("<%= uri %>")' ..."
43-
<%= timeout %> Rscript -e 'batchtools::doJobCollection("<%= uri %>", output = "<%= log.file %>")'
49+
echo "Rscript -e 'batchtools::doJobCollection()' ..."
50+
echo "- job name: '<%= job.name %>'"
51+
echo "- job log file: '<%= log.file %>'"
52+
echo "- job uri: '<%= uri %>'"
53+
<%= timeout %> Rscript -e 'batchtools::doJobCollection("<%= uri %>")'
4454
res=$?
4555
echo " - exit code: ${res}"
46-
echo "Command: Rscript -e 'batchtools::doJobCollection("<%= uri %>")' ... done"
56+
echo "Rscript -e 'batchtools::doJobCollection()' ... done"
57+
echo
4758

4859
<% if (length(shutdown) > 0) {
4960
writeLines(shutdown)

0 commit comments

Comments
 (0)