Script almost works... one error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script almost works... one error
# 1  
Old 02-28-2015
Script almost works... one error

Helo, i have written a bash script for running my calculations. anyway, according to shellcheck the error is somewhere in the while loop or in the if condition.

so the idea of this script is:
submit a job with a name.
while it is in the queue it has a job ID number.
after the job is done i want to proceed with further ORDERS, for this i need a while loop and a if condition

the script:

Code:
#!/bin/bash -l

#Name of the job gets defined
my_job_name='NEB3'
#Name of the folder is defined.
calcname='3rd_NEB-NH-off_to_BHNH-ortho'


[
#creating job directories etc.
]

cd /job_path/NEB_jobs/jobf_${my_job_name}
sbatch job_${my_job_name}

#Id of the job in the queue is registered
my_id=squeue -u myname | sed -n "/${my_job_name}/ {s/[\ ].*//; p}"


while sleep 30; do
        if [ "${my_id}" != squeue -u myname | sed -n "/${my_job_name}/ {s/[\ ].*//; p}" ]; then
        break
done


#cp folders 
#further ORDERS


with this order:
Code:
squeue -u myname | sed -n "/${my_job_name}/ {s/[\ ].*//; p}"

i receive the job id in numbers when i type in the shell. yet i dont know if these numbers are stored as a string or integers.

with regards

---------- Post updated at 08:41 AM ---------- Previous update was at 07:40 AM ----------

so now i've changed the while loop and it works almost:
Code:
#!/bin/bash -l

#Name of the job gets defined
my_job_name='NEB3'
#Name of the folder is defined.
calcname='3rd_NEB-NH-off_to_BHNH-ortho'


[
#creating job directories etc.
]

cd /job_path/NEB_jobs/jobf_${my_job_name}
sbatch job_${my_job_name}

#Id of the job in the queue is registered
my_id=squeue -u myname | sed -n "/${my_job_name}/ {s/[\ ].*//; p}"


while sleep 30; do
        temp_id=&(squeue -u myname | sed -n "/${my_job_name}/ {s/[\ ].*//; p}")
                if [ "${my_id}" != "${temp_id}" ]; then
                        break
                fi
done


FOLLOWING_ORDERS


what does not work, are the FOLOWING_ORDERDS. Does "break" in the while loop terminate the wole bashscrpit?

Last edited by carborane; 02-28-2015 at 08:47 AM..
# 2  
Old 02-28-2015
Quote:
Originally Posted by carborane
what does not work, are the FOLOWING_ORDERDS. Does "break" in the while loop terminate the wole bashscrpit?
No, but - regardless of wether it works or not - i suggest not to use break anyway. It is a concealed GOTO and you shouldn't need it nor use it. Do it like this:

Code:
typeset -i flag=0
while [ $flag -eq 0 ] ; do
     if [ <some condition> ] ; then
          flag=1
     else
          sleep 30
     fi
done

And, by the way:
Code:
temp_id=&(squeue -u myname | sed -n "/${my_job_name}/ {s/[\ ].*//; p}")

what is this supposed to do? I can understand most of it, but what should:

Code:
variable=&(command)

do?

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
Old 02-28-2015
Code:
variable=&(command)

oh yes i messed this up.

it should be: $ instead of &.

yeah i'll try the while loop, thank you

Last edited by carborane; 02-28-2015 at 11:20 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script works, but I think it could be better and faster

Hi All, I'm new to the forum and to bash scripting. I did some stuff with VB.net, Batch, and VBScripting in the past, but because I shifted over to Linux, I am learning to script in Bash at this moment. So bear with me if I seem to script like a newbie, that's just because I am ;-) OK, I... (9 Replies)
Discussion started by: cornelvis
9 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. Shell Programming and Scripting

Perl error in batch command but works one at a time

In the below perl executes if one file is processed perfect. However, when multiple files are processed in batch which is preferred I get the below error that I can not seem to fix it as the '' necessary for the command to execute, but seem to only work for one -arg option. Thank you :). ... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

Script works but doesn't?

Hi everyone I'm new here so and I'm just starting to learn a bit of Solaris and I'm working on repairing 10 year old scripts for our system here at work. When I execute the commands at my prompt everything go's through smooth. I'm using gedit to edit my code because I'm still getting used to the... (4 Replies)
Discussion started by: 82280zx
4 Replies

5. UNIX for Dummies Questions & Answers

Works on command line but not in script

Hey guys. Hopefully this is an easy one but having reference similar problems on the web I still can't fix it. I am doing a recursive find and replace from a script. Of course I could just run the damn thing from the command line but it's bugging me now and want to get it working. grep -rl... (4 Replies)
Discussion started by: anthonyjstewart
4 Replies

6. Shell Programming and Scripting

Script works with bash 3.0 but not 3.2.

Hello, So my knowledge of bash scripting is not that great and I have been trying to solve this problem on my own for awhile to no avail. Here's the error I get when running it with an OS that uses bash 3.2.x: testagain.sh: line 10: *-1: syntax error: operand expected (error token is... (2 Replies)
Discussion started by: forkandspoon
2 Replies

7. UNIX for Dummies Questions & Answers

find .... -exec rm .... \; works, but gives an error

I am using find to get all the instances of a given directory name, then remove those directories with a -exec rm command. here is an example: mkdir -p foo/bar find foo -name bar -exec rm -rf {} \; foo will get deleted as I desired, however this pops out on standard error: find: foo/bar:... (3 Replies)
Discussion started by: Afifi
3 Replies

8. UNIX for Dummies Questions & Answers

Error: `mv olddir/ newdir/ ` never works on new version of bash?

Suppose you have a directory called "olddir" exists but no "newdir", you want to rename "olddir" to"newdir" In previous versions (at least in 2.05b.0) of bash, you can try mv olddir/ newdir/ OR mv olddir/ newdir But in new versions of bash, if you mv olddir/ newdir/ BASH panics: mv:... (5 Replies)
Discussion started by: meili100
5 Replies

9. Shell Programming and Scripting

perl - how come this script works?

#!/usr/bin/perl open (DATA, file.txt); @array = <DATA>; close (DATA); open (DATA, ">$file.txt"); for (@array) { s/text/replace text/; push(@contents,$_); } seek(DATA, 0, 0); print DATA (@contents); close(DATA); could someone please explain how this works. i've been... (3 Replies)
Discussion started by: mjays
3 Replies

10. Shell Programming and Scripting

Script works fine until I | more

Hello all, This beats me. I have a script that executes some commands and redirects their output to some text files that I will parse. The commands are along the lines of: dsmadmc -id=admin -pa=admin -outfile=/home/tools/qlog.txt q log f=d If I just run the script it works. If I execute... (2 Replies)
Discussion started by: Skovian
2 Replies
Login or Register to Ask a Question