From: Renaud Barate Date: Fri, 9 Jan 2015 16:16:09 +0000 (+0100) Subject: Fix some bashisms and potential errors in generated shell scripts X-Git-Tag: V2_3_0~2 X-Git-Url: http://git.salome-platform.org/gitweb/?p=tools%2Flibbatch.git;a=commitdiff_plain;h=754f4636e4c914715ab50db8604325e2c872f223 Fix some bashisms and potential errors in generated shell scripts --- diff --git a/src/LSF/BatchManager_LSF.cxx b/src/LSF/BatchManager_LSF.cxx index 3ab7996..596551c 100644 --- a/src/LSF/BatchManager_LSF.cxx +++ b/src/LSF/BatchManager_LSF.cxx @@ -219,7 +219,7 @@ namespace Batch { tempOutputFile << "cd " << workDir << endl ; // generate nodes file - tempOutputFile << "LIBBATCH_NODEFILE=`mktemp nodefile-XXXXXXXXXX` || exit 1" << endl; + tempOutputFile << "LIBBATCH_NODEFILE=$(mktemp nodefile-XXXXXXXXXX) || exit 1" << endl; tempOutputFile << "bool=0" << endl; tempOutputFile << "for i in $LSB_MCPU_HOSTS; do" << endl; tempOutputFile << " if test $bool = 0; then" << endl; diff --git a/src/Local/BatchManager_Local.cxx b/src/Local/BatchManager_Local.cxx index 2dd28ee..7121ca8 100644 --- a/src/Local/BatchManager_Local.cxx +++ b/src/Local/BatchManager_Local.cxx @@ -302,7 +302,7 @@ namespace Batch { } else { #endif - tempOutputFile << "#!/bin/sh" << endl; + tempOutputFile << "#!/bin/sh -f" << endl; tempOutputFile << "cd " << workDir << endl; // Optional parameters (system limits on the job process) @@ -332,10 +332,17 @@ namespace Batch { tempOutputFile << "export " << iter->first << "=" << iter->second << endl; } - // generate nodes file - tempOutputFile << "LIBBATCH_NODEFILE=`mktemp nodefile-XXXXXXXXXX`" << endl; - for (int i=0 ; i> $LIBBATCH_NODEFILE" << endl; + // generate nodes file (one line per required proc) + tempOutputFile << "LIBBATCH_NODEFILE=$(mktemp nodefile-XXXXXXXXXX)" << endl; + tempOutputFile << "i=" << nbproc << endl; + tempOutputFile << "hn=$(hostname)" << endl; + tempOutputFile << "{" << endl; + tempOutputFile << "while [ $i -gt 0 ]" << endl; + tempOutputFile << "do" << endl; + tempOutputFile << " echo \"$hn\"" << endl; + tempOutputFile << " i=$((i-1))" << endl; + tempOutputFile << "done" << endl; + tempOutputFile << "} > \"$LIBBATCH_NODEFILE\"" << endl; tempOutputFile << "export LIBBATCH_NODEFILE" << endl; // Launch the executable @@ -374,7 +381,7 @@ namespace Batch { tempOutputFile << " 1>" << stdoutFile << " 2>" << stderrFile << endl; // Remove the node file - tempOutputFile << "rm $LIBBATCH_NODEFILE" << endl; + tempOutputFile << "rm \"$LIBBATCH_NODEFILE\"" << endl; #ifdef WIN32 } diff --git a/src/Slurm/BatchManager_Slurm.cxx b/src/Slurm/BatchManager_Slurm.cxx index 894e231..3c6c131 100644 --- a/src/Slurm/BatchManager_Slurm.cxx +++ b/src/Slurm/BatchManager_Slurm.cxx @@ -124,7 +124,7 @@ namespace Batch { ofstream tempOutputFile; string tmpFileName = Utils::createAndOpenTemporaryFile("slurm-script", tempOutputFile); - tempOutputFile << "#!/bin/bash" << endl; + tempOutputFile << "#!/bin/sh -f" << endl; tempOutputFile << "#SBATCH --output=" << workDir << "/logs/output.log." << rootNameToExecute << endl; tempOutputFile << "#SBATCH --error=" << workDir << "/logs/error.log." << rootNameToExecute << endl; @@ -164,8 +164,8 @@ namespace Batch { } // generate nodes file - tempOutputFile << "LIBBATCH_NODEFILE=`mktemp nodefile-XXXXXXXXXX`" << endl; - tempOutputFile << "srun hostname > $LIBBATCH_NODEFILE" << endl; + tempOutputFile << "LIBBATCH_NODEFILE=$(mktemp nodefile-XXXXXXXXXX)" << endl; + tempOutputFile << "srun hostname > \"$LIBBATCH_NODEFILE\"" << endl; tempOutputFile << "export LIBBATCH_NODEFILE" << endl; // Launch the executable @@ -182,7 +182,7 @@ namespace Batch { tempOutputFile << endl; // Remove the node file - tempOutputFile << "rm $LIBBATCH_NODEFILE" << endl; + tempOutputFile << "rm \"$LIBBATCH_NODEFILE\"" << endl; tempOutputFile.flush(); tempOutputFile.close();