Find the answer to your Linux question:
Results 1 to 4 of 4

Thread: while in while?

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    while in while?


    Hello,

    here someone introduced code on how to do multithreaded command in bash:

    processName=myprocess

    while true
    do
    if [ $(ps -ef |grep -v grep|grep ${processName} |wc -l) -le 4 ]
    then
    do something
    break
    fi
    sleep 5
    done
    I need to add this code in it (instead of "do something"):

    while read proxy;do
    curlresult=$(curl $proxy $url --connect-timeout 8 --max-time 20)
    if [[ "$curlresult" == *"meta"* ]];then
    echo "$proxy - traffic goes thru this proxy"
    echo $proxy >> proxieschecked.txt

    else

    echo "$proxy - it failed to connect in time"
    fi

    wc -l < proxieschecked.txt
    done < $proxyfile
    i dont think its possible to do 2 while? Any idea on how to merge it?

  2. #2
    of course it's possible. what's the problem?

    use ``pgrep'' instead of those pipes.

  3. #3
    please how is it possible to do what im asking in my first post?

    first While makes a loop and i need to make another loop from within that while. (while in while)

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    1,005
    What do you mean how is it possible? It's just possible.

    while true
    do
    while true
    do
    ...
    done
    done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •