Fetch the repository succeeded.
This action will force synchronization from chuanjiao10/kasini3000, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
#建议保存编码为:bom头 + utf8
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[Alias("ipaddress")][String]$目的ip地址,
[Alias("port")][uint16]$端口 = 22,
[ValidateNotNullOrEmpty()]
[Alias("user")][String]$用户名 = 'root',
[String]$ssh_key_file_path = '',
[Alias('file')][String]$ps1脚本文件名,
[Alias("allparameter")]$传入参数,
[parameter(Position = 0)][Alias("scriptblock")][scriptblock]$powershell代码块 = { },
$复制主控机node_script目录到被控机 = $false
)
function yg严格测试布尔型变量($被测试的布尔形变量)
{
if (($被测试的布尔形变量 -eq 1) -or ($被测试的布尔形变量 -eq $true) -or ($被测试的布尔形变量 -eq 'true'))
{
return $true
}
elseif (($被测试的布尔形变量 -eq 0) -or ($被测试的布尔形变量 -eq $false) -or ($被测试的布尔形变量 -eq 'false'))
{
return $false
}
else
{
Write-Error '错误:不合法的布尔型值,错误码999'
exit 999
}
}
[bool]$复制主控机node_script目录到被控机 = yg严格测试布尔型变量 $复制主控机node_script目录到被控机
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'
}
& "${global:kasini3000目录}/zkj_从主控机到linux被控机_ssh_knowhost免yes.ps1"
if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
Write-Error "应该使用另一个脚本!"
exit 21
}
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Warning '本脚本限制:需要用户交互输入密码,无法自动。'
}
else
{
Write-Warning 'Limitation of this script: It requires the user to enter the password interactively, not automatically.'
}
if ( ($ps1脚本文件名 -eq $null) -or ($ps1脚本文件名 -eq '') )
{
#这段代码在run_win2linux_key_pwd.ps1,run_win2win5985_pwd.ps1,run_linux2linux_key_pwd.ps1,k-commit.ps1
$有脚本文件 = $false
if ( ($powershell代码块.Ast.Extent.Text -eq '{ }') -or ($powershell代码块.Ast.Extent.Text -eq '{}') )
{
Write-Error "错误:没有输入脚本文件名,同时也没有输入代码块"
exit 15
}
else
{
if (& 'kcd_被控机运行的代码块_含有kcd.ps1' -输入脚本代码块 $powershell代码块)
{
Write-Error '错误:脚本内含有kcd等关键字'
exit 19
}
}
}
else
{
$有脚本文件 = $true
if ( ($powershell代码块.Ast.Extent.Text -eq '{ }') -or ($powershell代码块.Ast.Extent.Text -eq '{}') )
{
}
else
{
Write-Error "错误:有输入脚本文件名,同时有输入代码块"
exit 16
}
if (Test-Path -LiteralPath $ps1脚本文件名)
{
if (& 'kcd_被控机运行的脚本_含有kcd.ps1' -输入脚本文件名 $ps1脚本文件名)
{
Write-Error '错误!脚本内含有kcd等关键字'
exit 18
}
}
else
{
Write-Error "找不到脚本文件"
exit 17
}
}
if ($IsLinux -eq $True)
{
if ($复制主控机node_script目录到被控机 -eq $true)
{
& 'cpn21复制主控机node_script目录到当前被控机.ps1'
}
$端口通了 = & '/etc/kasini3000/tcp--ping-v5.ps1' -MyComputerName $目的ip地址 -port $端口 -Quiet
if ($端口通了 -eq $true)
{
}
else
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:被控机端口不通。错误码24"
}
else
{
Write-Error "error:node port cloesd.exit 24"
}
exit 24
}
if ($ssh_key_file_path -eq '')
{
Write-Verbose '使用ssh密码,连接开始'
$private:连接l2l01 = New-PSSession -HostName ${目的ip地址} -Port $端口 -UserName $用户名
if ( ($private:连接l2l01 -eq $null) -or ($private:连接l2l01 -eq '') )
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:使用密码连接失败。错误码25"
}
else
{
Write-Error "error:node port cloesd.exit 25"
}
exit 25
}
}
else
{
Write-Verbose '使用ssh秘钥,连接开始'
$private:连接l2l01 = New-PSSession -HostName ${目的ip地址} -Port $端口 -UserName $用户名 -KeyFilePath $ssh_key_file_path
if ( ($private:连接l2l01 -eq $null) -or ($private:连接l2l01 -eq '') )
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "错误:使用密码连接失败。错误码26"
}
else
{
Write-Error "error:node port cloesd.exit 26"
}
exit 26
}
}
Write-Verbose '连接成功。现在开始执行命令:'
$主控机公钥sha1 = Get-FileHash -Algorithm sha1 -LiteralPath "${global:kasini3000_data_path}\ssh_key_files_old1\authorized_keys"
$被控机公钥sha1 = Invoke-Command -Session $private:连接l2l01 -ScriptBlock { Get-FileHash -Algorithm sha1 -LiteralPath '/root/.ssh/authorized_keys' }
Write-Verbose ("公钥: {0} '---' {1} " -f ${主控机公钥sha1}.Hash,${被控机公钥sha1}.Hash)
if ($主控机公钥sha1.Hash -ne $被控机公钥sha1.Hash)
{
Write-Verbose "主控机-被控机之间,公钥有不同"
Copy-Item -LiteralPath "${global:kasini3000_data_path}\ssh_key_files_old1\authorized_keys" -Destination '/root/.ssh/' -ToSession $private:连接l2l01 -Force
}
[scriptblock]$private:cmd1 = `
{
Test-Path -LiteralPath '/etc/kasini3000'
}
$private:返回 = Invoke-Command -Session $private:连接l2l01 -ScriptBlock $private:cmd1
if ($private:返回 -eq $true)
{
}
else
{
[scriptblock]$private:cmd2 = `
{
mkdir '/etc/kasini3000'
}
Invoke-Command -Session $private:连接l2l01 -ScriptBlock $private:cmd2
$env:LANG = 'zh_CN.UTF-8'
Copy-Item -LiteralPath 'c:\ProgramData\kasini3000\node_script' -Destination '/etc/kasini3000' -Recurse -ToSession $private:连接l2l01
}
Invoke-Command -Session $private:连接l2l01 -ScriptBlock {
if (Test-Path '/etc/kasini3000/node_script/kasini3000/add_path.ps1')
{
& '/etc/kasini3000/node_script/kasini3000/add_path.ps1'
}
}
if ( $有脚本文件 -eq $true)
{
Invoke-Command -Session $private:连接l2l01 -FilePath $ps1脚本文件名 -ArgumentList $传入参数
}
else
{
Invoke-Command -Session $private:连接l2l01 -ScriptBlock $powershell代码块 -ArgumentList $传入参数
}
Write-Verbose '执行命令完成,即将断开连接。'
Remove-PSSession -Session $private:连接l2l01
}
Write-Verbose "完成在win2linux被控机【${目的ip地址}】上执行"
exit 0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。