Forking / Multi-Threaded Processes | Bash

前端 未结 8 1584
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 20:39

I would like to make a section of my code more efficient. I\'m thinking of making it fork off into multiple processes and have them execute 50/100 times at once, instead of

8条回答
  •  一生所求
    2020-11-30 20:49

    Based on what you all shared I was able to put this together:

    #!/usr/bin/env bash
    
    VAR1="192.168.1.20 192.168.1.126 192.168.1.36"
    
    for a in $VAR1; do { ssh -t -t $a -l Administrator "sudo softwareupdate -l"; } & done;
    WAITPIDS="$WAITPIDS "$!;...; wait $WAITPIDS
    echo "Script has finished"
    
    Exit 1
    

    This lists all the updates on the mac on three machines at once. Later on I used it to perform a software update for all machines when i CAT my ipaddress.txt

提交回复
热议问题