0

I want to execute the following command:

$SCHRODINGER/utilities/prepwizard [options] inputfile outputfile

$SCHRODINGER is the export of a software and in [options] I must control some variables of the calculation within the program that are not a problem:

for example:

$SCHRODINGER/utilities/prepwizard -watdist 0 fillsidechains -fillloops inputfile outputfile

I want to run it for multiple files with extension .pdb, but the issue is that I must run it one by one, not all at the same time. That is, as soon as one of the following executes, the output can also be in .pdb

I have written this code but it executes all the files to me at the time and it is not what I want:

for i in `ls *pdb`
do
$ SCHRODINGER / utilities / prepwizard [options] $i prep_$i 
done
  • 1
    This is so unclear, my head hurts. Do you really have a command called $?  Does it really take [options] (i.e., the literal string [options]) as an argument? Please do not respond in comments; edit your question and try hard to make it clearer and more complete. – Scott Oct 23 '18 at 3:00
  • 1
    Does prepwizard background the job? If so, does it write a process ID? I imagine that if the job is backgrounded you will need to monitor for it to finish - which you can do with "wait PID" if you know the PID, otherwise you may be able to get the PID with ps or pidof. – davidgo Oct 23 '18 at 4:12
  • Cross-posted: askubuntu.com/questions/1086275/… – muru Oct 23 '18 at 5:56
  • guys thank you very much for the help, it did not work for me, what I need is to first run Prepwizard (with $ SCHRODINGER / prepwizard [options] input output]) in for example 1.pdb and when this ends prepwizard is executed in 2. pdb, instead of that when 1.pdb and 2.pdb are executed at the time. – Andres Ballesteros Oct 23 '18 at 19:19
1

First, never parse the output of ls. Bad things can happen. Characters like \r and \n can actually be in filenames. To combat this, bash globbing is at your service:

for file in *.pdb
do
    ${SCHRODINGER}/utilities/prepwizard [options] "$file" "prep_${file}"
done

Or if you want a one-liner:

for file in *.pdb; do ${SCHRODINGER}/utilities/prepwizard [options] "$file" "prep_${file}"; done

This will execute each file IN TURN and will wait until the prepwizard application completes before continuing to the next file.

|improve this answer|||||
  • While the "don't pass output of ls" is not bad advice, the solution you have provided does not seem to address the problem - ie functionally I can't see the difference. – davidgo Oct 23 '18 at 4:16
  • I do not disagree with you. I provided it just as the proper way to handle the task through bash. Now, if it's processing all files concurrently, then I'd have to conclude that the application in question forks and sends itself to the background. If that's the case, then it's up to the program to not do that, not bash. – UtahJarhead Oct 23 '18 at 13:52
-1

To execute several commands sequentially (one being executed after the previous one has finished), you can separate them with a semicolon.

Thus, you could prepare all your commands in a string, and eval them after your loop:

allcommands=""
for i in `ls *pdb`
do
allcommands="$allcommands;SCHRODINGER options"
done
eval $allcommands
|improve this answer|||||
  • 2
    I don't see how this is in any way superior to the (failing) script the OP provided. – davidgo Oct 23 '18 at 4:13
  • @davidgo I agree, concatenating the commands actually won't do any better, as sequential processing is already the default behavior. Maybe I didn't understand the problem Andres is facing when he wants to avoid to execute "all the files at the same time". – Yoric Oct 23 '18 at 4:22
  • guys thank you very much for the help, it did not work for me, what I need is to first run Prepwizard (with $ SCHRODINGER / prepwizard [options] input output]) in for example 1.pdb and when this ends prepwizard is executed in 2. pdb, instead of that when 1.pdb and 2.pdb are executed at the time. – Andres Ballesteros Oct 23 '18 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.