1 Star 0 Fork 52

Sunday / kasini3000

forked from chuanjiao10 / kasini3000 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cpn2a复制主控机node_script目录到所有被控机.ps1 2.57 KB
一键复制 编辑 原始数据 按行查看 历史
#建议保存编码为:bom头 + utf8
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[Alias("log_file_fullname")][String]$日志文件全路径
)
if (Test-Path -LiteralPath $日志文件全路径)
{
}
else
{
$日志文件父目录 = Split-Path -LiteralPath $日志文件全路径
if (Test-Path -LiteralPath $日志文件父目录)
{
New-Item -Path $日志文件全路径 -ItemType File -Force
}
else
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:找不到日志文件父目录: ${日志文件父目录} ,错误码1"
}
else
{
Write-Error "Error: Could not find the log file parent directory: ${日志文件父目录} exit 1"
}
exit 1
}
}
function 写日志
{
param
(
[string]$被写入的log内容 = ''
)
$时间 = Get-Date -Format F
$输出信息 = "$时间 $被写入的log内容"
Add-Content -LiteralPath $日志文件全路径 -Value $输出信息 -Encoding UTF8
}
#main
if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
& 'c:\ProgramData\kasini3000\0k_source.ps1'
}
if ($IsLinux -eq $True)
{
& '/etc/kasini3000/0k_source.ps1'
}
& 'zd只读nodelist文件.ps1'
$win = 'win7','win8','win10','win11','win2008r2','win2012r2','win2016','win2019','win2022'
$linux = & "${PSScriptRoot}/linux_distribution_str.ps1"
$all = $win + $linux
foreach ($private:当前被控机 in $global:所有被控机)
{
& "${PSScriptRoot}/cdip.ps1" -被控机ip地址 $private:当前被控机.ip
if ($LASTEXITCODE -eq 0)
{
}
else
{
写日志 -被写入的log内容 ('错误:这个被控机连接失败:{0}' -f $private:当前被控机.ip)
Write-Error ('错误:这个被控机连接失败:{0}' -f $private:当前被控机.ip)
continue
}
if ($private:当前被控机.被控机os类型 -in $all)
{
写日志 -被写入的log内容 ('信息:这个被控机连接成功:{0}' -f $private:当前被控机.ip)
}
else
{
写日志 -被写入的log内容 ('错误:这个被控机连接失败:{0}' -f $private:当前被控机.ip)
Write-Error ('错误:这个被控机连接失败:{0}' -f $private:当前被控机.ip)
continue
}
c:\ProgramData\kasini3000\cpn21复制主控机node_script目录到当前被控机.ps1
if ($LASTEXITCODE -eq 0)
{
写日志 -被写入的log内容 ('信息:这个被控机复制文件成功:{0}' -f $private:当前被控机.ip)
}
else
{
写日志 -被写入的log内容 ('错误:这个被控机复制文件失败:{0}' -f $private:当前被控机.ip)
Write-Error ('错误:这个被控机复制文件失败:{0}' -f $private:当前被控机.ip)
}
}
exit 0
PowerShell
1
https://gitee.com/sundayisblue/kasini3000.git
git@gitee.com:sundayisblue/kasini3000.git
sundayisblue
kasini3000
kasini3000
master

搜索帮助