• Re: [gentoo-user] Any way to run multiple commands from single script i

    From Ramon Fischer@21:1/5 to All on Mon Mar 14 11:40:01 2022
    --------------UUhuY6r3W06DLGrHBzcDipVz
    Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: base64

    SGVsbG8gSm9vc3QsDQoNCkkgc3VwcG9zZSwgdGhhdCB5b3UgYXJlIHRhbGtpbmcgYWJvdXQg QmFzaCBzY3JpcHRzLg0KDQpJZiBzbywgeW91IG1heSBwdXQgZWFjaCBpbmRpdmlkdWFsIGNv bW1hbmQgaW4gYSBzdWJzaGVsbCBieSB1c2luZyBhbiANCmFtcGVyc2FuZCAoIiYiKSBhdCB0 aGUgZW5kIG9mIHRoZSBsaW5lLg0KDQpUaGlzIGV4YW1wbGVbMV0gc2hvd3MgaXQgbmljZWx5 Lg0KDQotUmFtb24NCg0KWzFdIDMuIFBhcmFsbGVsaXplIHJ1bm5pbmcgY29tbWFuZHMgYnkg Z3JhYmJpbmcgUElEcy46IA0KaHR0cHM6Ly93aWxsLWtlbGVoZXIuY29tL3Bvc3RzLzUtVXNl ZnVsLUJhc2gtUGF0dGVybnMuaHRtbA0KDQpPbiAxNC8wMy8yMDIyIDExOjEzLCBKLiBSb2Vs ZXZlbGQgd3JvdGU6DQo+IEhpLA0KPg0KPiBJIG9mdGVuIHB1dCBtdWx0aXBsZSBjb21tYW5k cyBpbnRvIGEgc2luZ2xlIGZpbGUvc2NyaXB0IHRvIGJlIHJ1biBpbiBzZXF1ZW5jZS4NCj4g KGVhY2ggbGluZSBjYW4gYmUgZXhlY3V0ZWQgaW5kaXZpZHVhbGx5LCB0aGVyZSBpcyBubyBk ZXBlbmRlbmN5KQ0KPg0KPiBJcyB0aGVyZSBhIHRvb2wvbWV0aG9kIHRvIGV4ZWN1dGUgbXVs dGlwbGUgbGluZXMvY29tbWFuZHMgc2ltdWx0YW5lb3VzbHk/IExpa2UNCj4gaGF2aW5nIDMg b3IgNCBydW4gdG9nZXRoZXIgYW5kIHdoZW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WcYR4bl r8YeNNf9pVj/0mWI+WqFovbCFreKfRN6nizo+SyF2JowOAcr1aiLLN226Xt/0urYU/Winc0njxdr mdUpOXvNsaX0oVuLOID/OqAcRxMNcU4ntgFzoN+ueXUdAq579d8EG0TTviqkDF8o+yn/5S1itvi/ Q8A=
    =k9m2
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Bj=c3=b6rn_Fischer?=@21:1/5 to All on Mon Mar 14 12:00:01 2022
    Hello Joost,

    Is there a tool/method to execute multiple lines/commands
    simultaneously? Like having 3 or 4 run together and when 1 is
    finished, it will grab the next one in the list?

    probably, GNU Parallel is what you are looking for:

    https://www.gnu.org/software/parallel/parallel.html#examples

    The tool can handle most variants of batch processing scenarios without
    the steep learning curve of fully fledged (clustered) job schedulers.

    Cheers,

    Björn

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andreas Fink@21:1/5 to J. Roeleveld on Mon Mar 14 12:20:01 2022
    On Mon, 14 Mar 2022 11:13:13 +0100
    "J. Roeleveld" <joost@antarean.org> wrote:

    Hi,

    I often put multiple commands into a single file/script to be run in sequence.
    (each line can be executed individually, there is no dependency)

    Is there a tool/method to execute multiple lines/commands simultaneously? Like
    having 3 or 4 run together and when 1 is finished, it will grab the next one in
    the list?

    I would prefer this over simply splitting the file as the different lines/ commands will not take the same amount of time.

    Thanks,

    Joost




    At the end there's a very rudimentary bash script to do this. I did not
    do much debugging (probably it fails already if max_jobs>#list_of_jobs).
    Anyway it's just making use of sending jobs to the background and "communicating" through a FIFO pipe (which you might want to delete at
    the end).
    #!/bin/bash

    list_of_jobs=("sleep 3" "sleep 5" "sleep 1" "sleep 10" "sleep 4")
    max_jobs=2
    my_fifo=/tmp/my_job_fifo
    write_to_fifo="yes"

    function run_job () {
    eval "$@"
    if [[ $write_to_fifo == "yes" ]]; then
    echo "Writing to fifo ($@)"
    echo 1 > ${my_fifo}
    fi
    echo Finished job "$@"
    }

    function read_and_start_job() {
    next_job_idx=0
    while [[ ${#list_of_jobs[@]} -gt $next_job_idx ]]; do
    while IFS= read -r line ; do
    echo "next_job_idx=${next_job_idx} total=${#list_of_jobs[@]}"
    if [[ $next_job_idx -lt ${#list_of_jobs[@]} ]] ; then
    job="${list_of_jobs[${next_job_idx}]}"
    echo "Executing: ${job}"
    run_job ${job} &
    let next_job_idx++
    else
    echo "Set write_to_fifo=no"
    write_to_fifo="no"
    fi
    done < ${my_fifo}
    done
    write_to_fifo="no"
    wait
    }

    rm -Rf ${my_fifo}
    mkfifo ${my_fifo}
    read_and_start_job &
    while [[ ${max_jobs} -gt 0 ]] ; do
    let max_jobs--
    echo 1 > ${my_fifo}
    done
    wait

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J. Roeleveld@21:1/5 to All on Mon Mar 14 21:40:01 2022
    On Monday, March 14, 2022 11:51:44 AM CET Björn Fischer wrote:
    Hello Joost,

    Is there a tool/method to execute multiple lines/commands
    simultaneously? Like having 3 or 4 run together and when 1 is
    finished, it will grab the next one in the list?

    probably, GNU Parallel is what you are looking for:

    https://www.gnu.org/software/parallel/parallel.html#examples

    The tool can handle most variants of batch processing scenarios without
    the steep learning curve of fully fledged (clustered) job schedulers.

    Thanks, this seems to do what I need it to do.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)