Bureaucrats, cc_docs_admin, cc_staff
2,879
edits
Line 23: | Line 23: | ||
== Running the same script in multiple directories == | == Running the same script in multiple directories == | ||
This example assumes that you have multiple directories, each with the same structure | This example assumes that you have multiple directories, each with the same structure and you want to run the same script in each directory. If the directories can be named with sequential numbers then the example above can be easily adapted. If they are not so systematic, then create a file with the names of the directories, like so: | ||
$ cat case_list | |||
pacific2016 | |||
pacific2017 | |||
atlantic2016 | |||
atlantic2017 | |||
{{File | {{File | ||
|name= | |name=directories_array.sh | ||
|language=bash | |language=bash | ||
|contents= | |contents= | ||
#!/bin/bash | #!/bin/bash | ||
#SBATCH -- | #SBATCH --time=0:15:00 | ||
#SBATCH -- | #SBATCH --array=1-4 | ||
echo "Starting task $SLURM_ARRAY_TASK_ID at $(date)" | |||
DIR=$(sed -n "${SLURM_ARRAY_TASK_ID}p" case_list) | |||
cd $DIR | cd $DIR | ||
# Place the code to execute here | # Place the code to execute here | ||
pwd | |||
ls | |||
}} | }} | ||
The file <code>case_list</code> should not be changed until all the tasks in the array have run, since it will be read each time a new task starts. | |||