Salome HOME
Fix some bashisms and potential errors in generated shell scripts
authorRenaud Barate <renaud.barate@edf.fr>
Fri, 9 Jan 2015 16:16:09 +0000 (17:16 +0100)
committerRenaud Barate <renaud.barate@edf.fr>
Fri, 13 Feb 2015 14:39:44 +0000 (15:39 +0100)
src/LSF/BatchManager_LSF.cxx
src/Local/BatchManager_Local.cxx
src/Slurm/BatchManager_Slurm.cxx

index 3ab7996260b237150d208e3b5b6b85ccf36dfd95..596551cc7ffa0f384b2b4667315fdf236cd81e48 100644 (file)
@@ -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;
index 2dd28ee4d406beaac49f9f351aac9157d5c974ff..7121ca8a96cef57efc34c81563a1cc6468d25460 100644 (file)
@@ -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<nbproc ; i++)
-      tempOutputFile << "echo `hostname` >> $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
     }
index 894e231e051474ca1e68c2336c3628d595b41945..3c6c1318dfd747f0b08939ab800baceab39ddbe4 100644 (file)
@@ -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();