Creating script with multiple job arrays


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating script with multiple job arrays
# 1  
Old 11-22-2018
Creating script with multiple job arrays

Hello everyone,

First of all this is my first post and im fairly new to working with Unix and creating scripts etc. so there will probably be wrong phrases used.

Lets get to my questions.

I have multiple scripts that submit Slurms/Jobs to the cluster starting like this and doing certain tasks:

Code:
#!/bin/bash
#SBATCH --partition=
#SBATCH --ntasks=
#SBATCH --time=0-10:00
#SBATCH --mem-per-cpu=48G
#SBATCH --job-name=basic_test
#SBATCH --mail-type=END,FAIL
#SBATCH --mail-user=           
#SBATCH --array=1-14

...


I have to run multiple of those scripts AFTER all the Slurms from the preceeding job are finished. Now I want to write a script that does exactly that. I already tried something like this:

Code:
#!/bin/bash

sbatch ~/testscript1.sh

wait

sbatch ~/testscript2.sh


the problem seems to be that the skript thinks that testscript1.sh is done as soon as it submitted all the slurms in the array to the server and then it starts testscript2.sh. This leads to problems because testscript2.sh works with some files that are only created when the submitted slurms from testscript1.sh are done.

Thank you for your help

Last edited by Scrutinizer; 11-22-2018 at 09:53 AM.. Reason: code tags
# 2  
Old 11-22-2018
From the man page:
Quote:
sbatch exits immediately after the script is successfully transferred
to the SLURM controller and assigned a SLURM job ID. The batch script
is not necessarily granted resources immediately, it may sit in the
queue of pending jobs for some time before its required resources
become available.
So the two commands will be executed immediately after one another. The wait statement has no function here, since no shell controlled background jobs are specified/used in the shell script.

So you will need to create dependencies between jobs. Did you checkout the -d option?
Quote:
-d, --dependency=<dependency_list>
Defer the start of this job until the specified dependencies
have been satisfied completed. [..]
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 11-22-2018
Thank you for the fast answer.... I didnt even think about looking into the manual -.-'
I will work with this and post results later
# 4  
Old 11-26-2018
Worked

I changed the script to work with

Code:
--dependency=singleton

This works for my purpose but might cause some compications for people running different jobs

I wanted to get

Code:
 --dependency=afterok:JobID

to work but I couldnt get it to work because I couldnt aquire the JobID from the first submitted job correctly.

I tried

Code:
JOBID1=$(sbatch ~/array.job)
JOBID1=$(echo $JOBID1 | sed -e "s/[a-zA-Z ]*//")

# removes anything but the job id

Code:
 JOBID2=$(sbatch --dependency=afterok:$JOBID1 ~/analyzeTE2.sh)

i also tried it without the echo | sed part but it wont work either way :/. I always get:

Code:
 sbatch: error: Batch job submission failed: Job dependency problem

this shows that the jobID isnt correct but I have no clue how to extract it correctly

------ Post updated at 10:19 AM ------

Ok problem is solved

I tried to define a new variable using the same name....

I just changed it like this:

Code:
 jid1=$(sbatch -p carl.p  ~/testing/testscript1.sh)

jid2=$(echo $jid1 | sed -e "s/[a-zA-Z ]*//")

sbatch -p carl.p --dependency=afterok:${jid2} ~/testing/testscript2.sh

and it worked




Moderator's Comments:
Mod Comment Don't tag the entire post; just the code/data parts

Last edited by RudiC; 11-26-2018 at 09:52 AM.. Reason: Corrected code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating a script to download images from multiple cameras using ghoto2

I should start by saying that I am totally new to linux... I am trying to create a script that downloads images from multiple cameras into a specific folder on my machine. Ideally renaming the images as they are downloaded. I have installed gphoto2 which as a command line interface that... (0 Replies)
Discussion started by: benpems
0 Replies

2. Shell Programming and Scripting

Shell script for creating multiple users with password

for UserName in `cat users` ; do useradd -d /u02 -s /usr/libexec/openssh/sftp-server -G ftp-users $UserName ; PassWord=$( echo $( tr '' '' <<< ${UserName:0:1} )${UserName:1} ) ; echo "$PassWord@123" | passwd $UserName --stdin ; done can some one explain what the bold text do Please use... (5 Replies)
Discussion started by: James0806
5 Replies

3. Shell Programming and Scripting

How to put the multiple job on-hold using shell script?

Hi.. I need to put multiple jobs on ON HOLD in Autosys.. please help me on this. For Example: 1)ABCD_EFGH_IJKL 2)abcd_efgh_ijkl (2 Replies)
Discussion started by: Maanjesh
2 Replies

4. Shell Programming and Scripting

How to write bash script for creating user on multiple Linux hosts?

I wonder whether someone can help me with what I'm trying to achieve Basically, the objective is one script to create new user on more than 70 linux hosts if required. Everything works apart from the highlighted part. It gave me an output passwd: Unknown user name ''. when try to set... (35 Replies)
Discussion started by: fugeulu
35 Replies

5. Shell Programming and Scripting

creating multiple sub-/directories using a shell script

0 Hi, I am looking for a way of creating multiple directories using the mkdir -p command in a shell script. I'm working with an Ubuntu machine and try to do something like that: #!/bin/sh ... (3 Replies)
Discussion started by: frymor
3 Replies

6. Shell Programming and Scripting

Need help in creating arrays using shell

Hi, I need help in creating a array in shell scirpt. I have a file which has following details. hostname devices device1 device 2 de abcdmhs10 1234 2343 2353 3343 3435 2343 bcdfmhs11 2343 2443 3434 8874 0343 3434 (5 Replies)
Discussion started by: jpkumar10
5 Replies

7. Shell Programming and Scripting

Multiple instances of the job in shell script.

Hi, Please let us know how to create a multiple instances of a job in the shell script. Thanks. Gangegowda K.G (1 Reply)
Discussion started by: Gangegowda
1 Replies

8. Shell Programming and Scripting

Joining two arrays and then creating a variable

Hello all... I'd like to create a variable from an array element from two arrays. In my search for answers I found this code for bash that joins two arrays and then started to work with it. I had got to work once and then foolishly without saving the code, I started to edit it for ksh and... (4 Replies)
Discussion started by: carlos25
4 Replies

9. Shell Programming and Scripting

Creating an unknown number of arrays

I need to create arrays like this: cnt=0 { while read myline; do if ];then firstpass="${myline##<meas>}" meas="${firstpass%%</meas>}" tempmeas="${meas%%;*}" MEAS$cnt=$tempmeas print $cnt print ${MEAS'$cnt'} ... (2 Replies)
Discussion started by: ajgwin
2 Replies

10. Shell Programming and Scripting

shell: creating different arrays based on function argument

hi, I was wondering if there was a good way to create an array within a function, where the name is based on a passed argument? I tried this: _____________________________ func(){ #take in 1st arg as the arrayname arrayName=$1 let i=0 while read line do arrayName=${line} let i+=1... (5 Replies)
Discussion started by: nix21
5 Replies
Login or Register to Ask a Question