win,linux,加 powershell 7 preview 版,若是 linux 则用 sshpass+ssh。
$a = get-content ip.txt
$a | ForEach-Object -ThrottleLimit 50 -Parallel {
# sshpass ssh ip 等
}
powershell [强] [简] 死你!
=========安装==========
你需要把 powershell 改成 powershell-preview,即安装非稳定版的 powershell。
centos7 及以上,安装 powershell:
curl -o /etc/yum.repos.d/microsoft.repo
https://packages.microsoft.com/config/rhel/7/prod.repo sudo yum remove -y powershell #删除旧版
sudo yum install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '
ubuntu1604:
sudo curl
https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo curl -o /etc/apt/sources.list.d/microsoft.list
https://packages.microsoft.com/config/ubuntu/16.04/prod.listsudo apt-get update
sudo apt-get remove -y powershell #删除旧版
sudo apt-get install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '
ubuntu1804:
sudo curl
https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo curl -o /etc/apt/sources.list.d/microsoft.list
https://packages.microsoft.com/config/ubuntu/18.04/prod.listsudo apt-get update
sudo apt-get remove -y powershell #删除旧版
sudo apt-get install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '
debian9:
sudo apt-get update
sudo apt-get install curl gnupg apt-transport-https
curl
https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64]
https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/microsoft.list'
sudo apt-get update
sudo apt-get remove -y powershell #删除旧版
sudo apt-get install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '
=========资料==========
┏┳━━━━━━━━━━━┓
┃┃███████████┃
┃┃███████████┃
┣┫███████┏━┓█┃
┃┃███████┃P┃█┃
┃┃███████┃O┃█┃
┃┃███秘███┃W┃█┃
┣┫███████┃E┃█┃
┃┃███████┃R┃█┃
┃┃███████┃S┃█┃
┃┃███████┃H┃█┃
┣┫███████┃E┃█┃
┃┃███籍███┃L┃█┃
┃┃███████┃L┃█┃
┃┃███████┗━┛█┃
┣┫███████████┃
┃┃██V7.0 preview3 ██┃
┃┃███████████┃
┗┻━━━━━━━━━━━┛
新增并发参数
| ForEach-Object -Parallel
例子:
1
get-content ip.txt |foreach-object -Parallel{ ping.exe $_ }
2
Get-Content /powershell/ip.txt |ForEach-Object -Parallel {if (Test-Connection -Count 1 -TargetName $_ -Quiet) {$_} } 6>$null
3
$a = 1..100
$a | ForEach-Object -ThrottleLimit 5 -Parallel {
Write-Host $_
Start-Sleep -Seconds 3
}
手册:
https://github.com/PowerShell/PowerShell-RFC/blob/master/4-Experimental-Accepted/RFC0044-ForEach-Parallel-Cmdlet.md参数:
-Parallel
-ThrottleLimit
-TimeoutSeconds parameter takes an integer that specifies the maximum time to wait for completion before the command is aborted
-AsJob