run another process after the background process is complete

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












said i have looping script in file test.sh, i just want to running script "running_script2.sh" after the background process is complete, what i try like this, but it's not working .



for id in 1 2 3
do
bash running_script1.sh $id & (#complete 1 minute/looping)
done
wait
echo "running script2 ..."
bash running_script2.sh


its work when :



bash running_script1.sh 1 &
bash running_script1.sh 2 &
bash running_script1.sh 3 &
wait
echo "running script2 ..."
bash running_script2.sh


but its not efficient










share|improve this question























  • The first line of your example, the for statement, should have the literal word in between id and the numerals.
    – user1404316
    Aug 13 at 3:59











  • ups, I forgot to add 'in'
    – Anggoro Setiawan
    Aug 13 at 4:10














up vote
2
down vote

favorite












said i have looping script in file test.sh, i just want to running script "running_script2.sh" after the background process is complete, what i try like this, but it's not working .



for id in 1 2 3
do
bash running_script1.sh $id & (#complete 1 minute/looping)
done
wait
echo "running script2 ..."
bash running_script2.sh


its work when :



bash running_script1.sh 1 &
bash running_script1.sh 2 &
bash running_script1.sh 3 &
wait
echo "running script2 ..."
bash running_script2.sh


but its not efficient










share|improve this question























  • The first line of your example, the for statement, should have the literal word in between id and the numerals.
    – user1404316
    Aug 13 at 3:59











  • ups, I forgot to add 'in'
    – Anggoro Setiawan
    Aug 13 at 4:10












up vote
2
down vote

favorite









up vote
2
down vote

favorite











said i have looping script in file test.sh, i just want to running script "running_script2.sh" after the background process is complete, what i try like this, but it's not working .



for id in 1 2 3
do
bash running_script1.sh $id & (#complete 1 minute/looping)
done
wait
echo "running script2 ..."
bash running_script2.sh


its work when :



bash running_script1.sh 1 &
bash running_script1.sh 2 &
bash running_script1.sh 3 &
wait
echo "running script2 ..."
bash running_script2.sh


but its not efficient










share|improve this question















said i have looping script in file test.sh, i just want to running script "running_script2.sh" after the background process is complete, what i try like this, but it's not working .



for id in 1 2 3
do
bash running_script1.sh $id & (#complete 1 minute/looping)
done
wait
echo "running script2 ..."
bash running_script2.sh


its work when :



bash running_script1.sh 1 &
bash running_script1.sh 2 &
bash running_script1.sh 3 &
wait
echo "running script2 ..."
bash running_script2.sh


but its not efficient







bash background-process






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 13 at 4:11

























asked Aug 13 at 3:19









Anggoro Setiawan

304




304











  • The first line of your example, the for statement, should have the literal word in between id and the numerals.
    – user1404316
    Aug 13 at 3:59











  • ups, I forgot to add 'in'
    – Anggoro Setiawan
    Aug 13 at 4:10
















  • The first line of your example, the for statement, should have the literal word in between id and the numerals.
    – user1404316
    Aug 13 at 3:59











  • ups, I forgot to add 'in'
    – Anggoro Setiawan
    Aug 13 at 4:10















The first line of your example, the for statement, should have the literal word in between id and the numerals.
– user1404316
Aug 13 at 3:59





The first line of your example, the for statement, should have the literal word in between id and the numerals.
– user1404316
Aug 13 at 3:59













ups, I forgot to add 'in'
– Anggoro Setiawan
Aug 13 at 4:10




ups, I forgot to add 'in'
– Anggoro Setiawan
Aug 13 at 4:10










2 Answers
2






active

oldest

votes

















up vote
1
down vote













There is no semantic difference between



for id in 1 2 3
do
bash running_script1.sh $id & (#complete 1 minute/looping)
done


and



bash running_script1.sh 1 &
bash running_script1.sh 2 &
bash running_script1.sh 3 &
wait
echo "running script2 ..."
bash running_script2.sh


This demonstration script below runs little over 3s (you can time it) regardless of whether the condition command is true or false:



#!/bin/sh -eu
for i in 1 2 3; do
echo "sleep $i" > $i && chmod +x $i
done
if false; then
for i in 1 2 3; do
bash ./$i &
done
else
bash ./1 &
bash ./2 &
bash ./3 &
fi
wait


If you're still experiencing discrepancies, please post an mcve.






share|improve this answer



























    up vote
    0
    down vote













    Don't know whether this is a right approach but I have used screen to run script

    screen is a virtual terminal to run process in bg



    for id in 1 2 3
    do
    screen -d -m bash script1.sh $id
    done
    wait
    echo "running script2 ..."
    bash script2.sh


    screen -d -m will run the script and closes the screen after the script completes.

    I cannot get the output of script1 in standard output while using screen so I used a file to store the output of script1.






    share|improve this answer




















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462211%2frun-another-process-after-the-background-process-is-complete%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote













      There is no semantic difference between



      for id in 1 2 3
      do
      bash running_script1.sh $id & (#complete 1 minute/looping)
      done


      and



      bash running_script1.sh 1 &
      bash running_script1.sh 2 &
      bash running_script1.sh 3 &
      wait
      echo "running script2 ..."
      bash running_script2.sh


      This demonstration script below runs little over 3s (you can time it) regardless of whether the condition command is true or false:



      #!/bin/sh -eu
      for i in 1 2 3; do
      echo "sleep $i" > $i && chmod +x $i
      done
      if false; then
      for i in 1 2 3; do
      bash ./$i &
      done
      else
      bash ./1 &
      bash ./2 &
      bash ./3 &
      fi
      wait


      If you're still experiencing discrepancies, please post an mcve.






      share|improve this answer
























        up vote
        1
        down vote













        There is no semantic difference between



        for id in 1 2 3
        do
        bash running_script1.sh $id & (#complete 1 minute/looping)
        done


        and



        bash running_script1.sh 1 &
        bash running_script1.sh 2 &
        bash running_script1.sh 3 &
        wait
        echo "running script2 ..."
        bash running_script2.sh


        This demonstration script below runs little over 3s (you can time it) regardless of whether the condition command is true or false:



        #!/bin/sh -eu
        for i in 1 2 3; do
        echo "sleep $i" > $i && chmod +x $i
        done
        if false; then
        for i in 1 2 3; do
        bash ./$i &
        done
        else
        bash ./1 &
        bash ./2 &
        bash ./3 &
        fi
        wait


        If you're still experiencing discrepancies, please post an mcve.






        share|improve this answer






















          up vote
          1
          down vote










          up vote
          1
          down vote









          There is no semantic difference between



          for id in 1 2 3
          do
          bash running_script1.sh $id & (#complete 1 minute/looping)
          done


          and



          bash running_script1.sh 1 &
          bash running_script1.sh 2 &
          bash running_script1.sh 3 &
          wait
          echo "running script2 ..."
          bash running_script2.sh


          This demonstration script below runs little over 3s (you can time it) regardless of whether the condition command is true or false:



          #!/bin/sh -eu
          for i in 1 2 3; do
          echo "sleep $i" > $i && chmod +x $i
          done
          if false; then
          for i in 1 2 3; do
          bash ./$i &
          done
          else
          bash ./1 &
          bash ./2 &
          bash ./3 &
          fi
          wait


          If you're still experiencing discrepancies, please post an mcve.






          share|improve this answer












          There is no semantic difference between



          for id in 1 2 3
          do
          bash running_script1.sh $id & (#complete 1 minute/looping)
          done


          and



          bash running_script1.sh 1 &
          bash running_script1.sh 2 &
          bash running_script1.sh 3 &
          wait
          echo "running script2 ..."
          bash running_script2.sh


          This demonstration script below runs little over 3s (you can time it) regardless of whether the condition command is true or false:



          #!/bin/sh -eu
          for i in 1 2 3; do
          echo "sleep $i" > $i && chmod +x $i
          done
          if false; then
          for i in 1 2 3; do
          bash ./$i &
          done
          else
          bash ./1 &
          bash ./2 &
          bash ./3 &
          fi
          wait


          If you're still experiencing discrepancies, please post an mcve.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 13 at 14:31









          PSkocik

          17.2k24590




          17.2k24590






















              up vote
              0
              down vote













              Don't know whether this is a right approach but I have used screen to run script

              screen is a virtual terminal to run process in bg



              for id in 1 2 3
              do
              screen -d -m bash script1.sh $id
              done
              wait
              echo "running script2 ..."
              bash script2.sh


              screen -d -m will run the script and closes the screen after the script completes.

              I cannot get the output of script1 in standard output while using screen so I used a file to store the output of script1.






              share|improve this answer
























                up vote
                0
                down vote













                Don't know whether this is a right approach but I have used screen to run script

                screen is a virtual terminal to run process in bg



                for id in 1 2 3
                do
                screen -d -m bash script1.sh $id
                done
                wait
                echo "running script2 ..."
                bash script2.sh


                screen -d -m will run the script and closes the screen after the script completes.

                I cannot get the output of script1 in standard output while using screen so I used a file to store the output of script1.






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Don't know whether this is a right approach but I have used screen to run script

                  screen is a virtual terminal to run process in bg



                  for id in 1 2 3
                  do
                  screen -d -m bash script1.sh $id
                  done
                  wait
                  echo "running script2 ..."
                  bash script2.sh


                  screen -d -m will run the script and closes the screen after the script completes.

                  I cannot get the output of script1 in standard output while using screen so I used a file to store the output of script1.






                  share|improve this answer












                  Don't know whether this is a right approach but I have used screen to run script

                  screen is a virtual terminal to run process in bg



                  for id in 1 2 3
                  do
                  screen -d -m bash script1.sh $id
                  done
                  wait
                  echo "running script2 ..."
                  bash script2.sh


                  screen -d -m will run the script and closes the screen after the script completes.

                  I cannot get the output of script1 in standard output while using screen so I used a file to store the output of script1.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 13 at 4:46









                  Edwin Babu

                  13




                  13



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462211%2frun-another-process-after-the-background-process-is-complete%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)