0

I want to run another while read with different input file + python script after first one is finished. Example code:

#!/bin/bash
while read -r line;
do
    python3 script.py -d $line --output test
done < domain.txt && 
mv *.txt savehere && 
dos2unix savehere/* && 
sort savehere/*.txt | uniq > done.txt

I know I could do:

#!/bin/bash
while read -r line;
do
    python3 script.py -d $line --output test && 
    python3 script1337.py -d $line
done < domain.txt && 
mv *.txt savehere && 
dos2unix savehere/* && 
sort savehere/*.txt | uniq > done.txt

But this is not what I want - I need to use different input file and want to run script1337.py after script.py is finished going through domain.txt (it does not work with && because it accepts 1 argument).

3
  • You question is not clear. You show what you could do and then say you don't want to do that: what do you want to do? Jul 2 '20 at 18:40
  • 1
    Umm, you want to run another while loop? I suppose you don't mean to just well, have another one, like while read line; do this; done < file; while read line; do that; done anotherfile. But if not that, then, what?
    – ilkkachu
    Jul 2 '20 at 18:44
  • as I said, I want to wait for the script.py to finish going through domain.txt and then run script1337.py - the example was that I cannot use that as solution (because script.py is accepting one argument at time - which means that its gonna go right to script1337.py after it goes through first line in domain.txt) @glennjackman Jul 2 '20 at 18:44
0

There's also a while-free way:

xargs -L 1 -I '{}' python3 script.py -d \"'{}'\" --output test < domain.txt &&
xargs -L 1 -I '{}' python3 script1337.py -d \"'{}'\"           < scriptfile.txt &&
mv *.txt savehere && 
dos2unix savehere/* && 
sort savehere/*.txt | uniq > done.txt

It'd be less efficient though, since it calls the xargs external util.

0

You have

while read -r line; do 
    python3 script.py -d "$line" --output test
done < domain.txt \
  && mv *.txt savehere \
  && dos2unix savehere/* \
  && sort savehere/*.txt | uniq > done.txt

Do you want this, using grouping braces?

{
    while read -r line; do 
        python3 script.py -d "$line" --output test
    done < domain.txt
    while read -r line; do 
        python3 scripy1337.py -d "$line"
    done < other_input_file
} && mv *.txt savehere \
  && dos2unix savehere/* \
  && sort savehere/*.txt | uniq > done.txt
5
  • Thanks! however script1337.py is being completly skipped Jul 2 '20 at 19:27
  • 1
    I assume you noticed the filename other_input_file and replaced it with your actual filename, and you didn't just blindly cut and paste... Jul 2 '20 at 20:19
  • of course, everything is replaced correctly - if i change positions script1337.py with script.py then script.py is ignored and script1337.py executed Jul 2 '20 at 20:36
  • What is the exit status of script.py? Do you use set -e or set -o errexit? Jul 2 '20 at 21:28
  • those scripts are not made by me, however I can see that they both use sys.exit() Jul 2 '20 at 21:37
0
#!/bin/bash
#!/usr/bin/env python3
while read -r line; do  #foobar
    python3 script.py -d $line --output test #foobar
done < domain.txt && 
while read -r line; do  #foobar
    python3 script1337.py -d $line #foobar
done < scriptfile.txt && 
mv *.txt savehere && 
dos2unix savehere/* && 
sort savehere/*.txt | uniq > done.txt #foobar

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.