Shell Scripting - return to previous loop until process is completed then die/done

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











up vote
-1
down vote

favorite












I am writing a bash/shell script to automate some file filtering functions. Here is what I have written so far. Its based of a script I found online.



if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 ))
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
# here is where I would like it to loop until the filtering is complete
# then once the final file is > 0 stop/die/done
fi
fi
fi


I would like it loop until the final.txt has been created in the dir, I will add that part in, just need assistance on the loop or return function ( if return can be used to return to line 1 and start running the script again until the final.txt is created then die/done/stop)










share|improve this question















migrated from serverfault.com May 17 '15 at 20:43


This question came from our site for system and network administrators.














  • Take a look at shellcheck.net and please indent your code.
    – Cyrus
    May 17 '15 at 6:00










  • As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
    – LinSheller
    May 17 '15 at 6:06










  • I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
    – LinSheller
    May 17 '15 at 6:08






  • 2




    Also, what you're looking for is while instead of if on the first line. The man page for bash should tell you how it works.
    – Jenny D
    May 17 '15 at 6:13






  • 2




    you should probably be using [ -s filename ] for most of those wc -l tests,
    – mikeserv
    May 18 '15 at 1:35















up vote
-1
down vote

favorite












I am writing a bash/shell script to automate some file filtering functions. Here is what I have written so far. Its based of a script I found online.



if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 ))
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
# here is where I would like it to loop until the filtering is complete
# then once the final file is > 0 stop/die/done
fi
fi
fi


I would like it loop until the final.txt has been created in the dir, I will add that part in, just need assistance on the loop or return function ( if return can be used to return to line 1 and start running the script again until the final.txt is created then die/done/stop)










share|improve this question















migrated from serverfault.com May 17 '15 at 20:43


This question came from our site for system and network administrators.














  • Take a look at shellcheck.net and please indent your code.
    – Cyrus
    May 17 '15 at 6:00










  • As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
    – LinSheller
    May 17 '15 at 6:06










  • I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
    – LinSheller
    May 17 '15 at 6:08






  • 2




    Also, what you're looking for is while instead of if on the first line. The man page for bash should tell you how it works.
    – Jenny D
    May 17 '15 at 6:13






  • 2




    you should probably be using [ -s filename ] for most of those wc -l tests,
    – mikeserv
    May 18 '15 at 1:35













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am writing a bash/shell script to automate some file filtering functions. Here is what I have written so far. Its based of a script I found online.



if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 ))
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
# here is where I would like it to loop until the filtering is complete
# then once the final file is > 0 stop/die/done
fi
fi
fi


I would like it loop until the final.txt has been created in the dir, I will add that part in, just need assistance on the loop or return function ( if return can be used to return to line 1 and start running the script again until the final.txt is created then die/done/stop)










share|improve this question















I am writing a bash/shell script to automate some file filtering functions. Here is what I have written so far. Its based of a script I found online.



if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 ))
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
# here is where I would like it to loop until the filtering is complete
# then once the final file is > 0 stop/die/done
fi
fi
fi


I would like it loop until the final.txt has been created in the dir, I will add that part in, just need assistance on the loop or return function ( if return can be used to return to line 1 and start running the script again until the final.txt is created then die/done/stop)







linux bash shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Rui F Ribeiro

38.2k1475123




38.2k1475123










asked May 17 '15 at 5:33







LinSheller











migrated from serverfault.com May 17 '15 at 20:43


This question came from our site for system and network administrators.






migrated from serverfault.com May 17 '15 at 20:43


This question came from our site for system and network administrators.













  • Take a look at shellcheck.net and please indent your code.
    – Cyrus
    May 17 '15 at 6:00










  • As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
    – LinSheller
    May 17 '15 at 6:06










  • I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
    – LinSheller
    May 17 '15 at 6:08






  • 2




    Also, what you're looking for is while instead of if on the first line. The man page for bash should tell you how it works.
    – Jenny D
    May 17 '15 at 6:13






  • 2




    you should probably be using [ -s filename ] for most of those wc -l tests,
    – mikeserv
    May 18 '15 at 1:35

















  • Take a look at shellcheck.net and please indent your code.
    – Cyrus
    May 17 '15 at 6:00










  • As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
    – LinSheller
    May 17 '15 at 6:06










  • I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
    – LinSheller
    May 17 '15 at 6:08






  • 2




    Also, what you're looking for is while instead of if on the first line. The man page for bash should tell you how it works.
    – Jenny D
    May 17 '15 at 6:13






  • 2




    you should probably be using [ -s filename ] for most of those wc -l tests,
    – mikeserv
    May 18 '15 at 1:35
















Take a look at shellcheck.net and please indent your code.
– Cyrus
May 17 '15 at 6:00




Take a look at shellcheck.net and please indent your code.
– Cyrus
May 17 '15 at 6:00












As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
– LinSheller
May 17 '15 at 6:06




As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
– LinSheller
May 17 '15 at 6:06












I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
– LinSheller
May 17 '15 at 6:08




I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
– LinSheller
May 17 '15 at 6:08




2




2




Also, what you're looking for is while instead of if on the first line. The man page for bash should tell you how it works.
– Jenny D
May 17 '15 at 6:13




Also, what you're looking for is while instead of if on the first line. The man page for bash should tell you how it works.
– Jenny D
May 17 '15 at 6:13




2




2




you should probably be using [ -s filename ] for most of those wc -l tests,
– mikeserv
May 18 '15 at 1:35





you should probably be using [ -s filename ] for most of those wc -l tests,
– mikeserv
May 18 '15 at 1:35











1 Answer
1






active

oldest

votes

















up vote
0
down vote













I don't really understand some parts of your code.
1) Does the script filefilter.sh performs the filtering?
2) If yes, in what condition will it filters (eg. $service exist)
3) Are you filtering selected services or all processes running



Indent is pretty important in scripting as you can easily spot the loops clearly



[ Your Code ]:



if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 )) #There is no condition required for the else-loop

if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh

else
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 )) #There is no condition required for the else-loop

if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
#You can use the exit command to stop the loop base on the condition you want

fi
fi
fi





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: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    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%2f203966%2fshell-scripting-return-to-previous-loop-until-process-is-completed-then-die-do%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown
























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I don't really understand some parts of your code.
    1) Does the script filefilter.sh performs the filtering?
    2) If yes, in what condition will it filters (eg. $service exist)
    3) Are you filtering selected services or all processes running



    Indent is pretty important in scripting as you can easily spot the loops clearly



    [ Your Code ]:



    if (( $(ps -ef | grep $service | wc -l) > 0 ))
    then
    echo "$service is not done" >> /root/test.txt
    else
    (( $(wc -l /root/filter/first.txt) > 0 )) #There is no condition required for the else-loop

    if (( $(ps -ef | grep $service | wc -l) < 0 ))
    then
    ./root/filter/filefilter.sh

    else
    (( $(ls | grep /root/filter/final.txt | wc -l) > 0 )) #There is no condition required for the else-loop

    if (( $(ps -ef | grep awk | wc -l) > 0 ))
    then
    (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
    else
    #You can use the exit command to stop the loop base on the condition you want

    fi
    fi
    fi





    share|improve this answer
























      up vote
      0
      down vote













      I don't really understand some parts of your code.
      1) Does the script filefilter.sh performs the filtering?
      2) If yes, in what condition will it filters (eg. $service exist)
      3) Are you filtering selected services or all processes running



      Indent is pretty important in scripting as you can easily spot the loops clearly



      [ Your Code ]:



      if (( $(ps -ef | grep $service | wc -l) > 0 ))
      then
      echo "$service is not done" >> /root/test.txt
      else
      (( $(wc -l /root/filter/first.txt) > 0 )) #There is no condition required for the else-loop

      if (( $(ps -ef | grep $service | wc -l) < 0 ))
      then
      ./root/filter/filefilter.sh

      else
      (( $(ls | grep /root/filter/final.txt | wc -l) > 0 )) #There is no condition required for the else-loop

      if (( $(ps -ef | grep awk | wc -l) > 0 ))
      then
      (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
      else
      #You can use the exit command to stop the loop base on the condition you want

      fi
      fi
      fi





      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        I don't really understand some parts of your code.
        1) Does the script filefilter.sh performs the filtering?
        2) If yes, in what condition will it filters (eg. $service exist)
        3) Are you filtering selected services or all processes running



        Indent is pretty important in scripting as you can easily spot the loops clearly



        [ Your Code ]:



        if (( $(ps -ef | grep $service | wc -l) > 0 ))
        then
        echo "$service is not done" >> /root/test.txt
        else
        (( $(wc -l /root/filter/first.txt) > 0 )) #There is no condition required for the else-loop

        if (( $(ps -ef | grep $service | wc -l) < 0 ))
        then
        ./root/filter/filefilter.sh

        else
        (( $(ls | grep /root/filter/final.txt | wc -l) > 0 )) #There is no condition required for the else-loop

        if (( $(ps -ef | grep awk | wc -l) > 0 ))
        then
        (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
        else
        #You can use the exit command to stop the loop base on the condition you want

        fi
        fi
        fi





        share|improve this answer












        I don't really understand some parts of your code.
        1) Does the script filefilter.sh performs the filtering?
        2) If yes, in what condition will it filters (eg. $service exist)
        3) Are you filtering selected services or all processes running



        Indent is pretty important in scripting as you can easily spot the loops clearly



        [ Your Code ]:



        if (( $(ps -ef | grep $service | wc -l) > 0 ))
        then
        echo "$service is not done" >> /root/test.txt
        else
        (( $(wc -l /root/filter/first.txt) > 0 )) #There is no condition required for the else-loop

        if (( $(ps -ef | grep $service | wc -l) < 0 ))
        then
        ./root/filter/filefilter.sh

        else
        (( $(ls | grep /root/filter/final.txt | wc -l) > 0 )) #There is no condition required for the else-loop

        if (( $(ps -ef | grep awk | wc -l) > 0 ))
        then
        (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
        else
        #You can use the exit command to stop the loop base on the condition you want

        fi
        fi
        fi






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jun 3 '15 at 8:08









        Win.T

        4721612




        4721612



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f203966%2fshell-scripting-return-to-previous-loop-until-process-is-completed-then-die-do%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay