本文整理匯總了Golang中github.com/eaciit/sshclient.SshSetting.RunCommandSshAsMap方法的典型用法代碼示例。如果您正苦於以下問題:Golang SshSetting.RunCommandSshAsMap方法的具體用法?Golang SshSetting.RunCommandSshAsMap怎麽用?Golang SshSetting.RunCommandSshAsMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/eaciit/sshclient.SshSetting
的用法示例。
在下文中一共展示了SshSetting.RunCommandSshAsMap方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runWithTimeout
func (a *Application) runWithTimeout(sshSetting sshclient.SshSetting, cmd string) (string, error) {
timeout := time.Second * time.Duration(5)
cRunCommand := make(chan string, 1)
var res string
go func(res *string) {
temp, err := sshSetting.RunCommandSshAsMap(cmd)
*res = temp[0].Output
if err != nil {
cRunCommand <- err.Error()
} else {
cRunCommand <- ""
}
}(&res)
errorMessage := ""
select {
case receiveRunCommandOutput := <-cRunCommand:
errorMessage = receiveRunCommandOutput
case <-time.After(time.Second * time.Duration(timeout)):
errorMessage = ""
}
if strings.TrimSpace(errorMessage) != "" {
return "", errors.New(errorMessage)
}
return strings.TrimSpace(res), nil
}
示例2: ProcessSetup
//.........這裏部分代碼省略.........
pathstring := []string{dataServers.DataPath, "langenvironment", "installer"}
var installShPath, uninstallShPath string
if strings.ToLower(dataServers.OS) == strings.ToLower(dataInstaller.OS) {
// targetLang := new(colonycore.InstalledLang)
// targetLang.Lang = eachLang.Language
// for _, eachLang := range dataServers.InstalledLang {
// if eachLang.Lang == targetLang.Lang {
// targetLang = eachLang
// break
// }
// }
if eachLang.Language == LANG_GO {
pathstring = append(pathstring, LANG_GO)
pathstring = append(pathstring, dataServers.OS)
sourcePath = filepath.Join(leSourcePath, LANG_GO, dataServers.OS, dataInstaller.InstallerSource)
destinationPath = strings.Join(pathstring, serverPathSeparator)
installShPath = filepath.Join(leSourcePath, LANG_GO, dataServers.OS, "install.sh")
uninstallShPath = filepath.Join(leSourcePath, LANG_GO, dataServers.OS, "uninstall.sh")
} else if eachLang.Language == LANG_JAVA {
pathstring = append(pathstring, LANG_JAVA)
pathstring = append(pathstring, dataServers.OS)
sourcePath = filepath.Join(leSourcePath, LANG_JAVA, dataServers.OS, dataInstaller.InstallerSource)
destinationPath = strings.Join(pathstring, serverPathSeparator)
installShPath = filepath.Join(leSourcePath, LANG_JAVA, dataServers.OS, "install.sh")
uninstallShPath = filepath.Join(leSourcePath, LANG_JAVA, dataServers.OS, "uninstall.sh")
} else if eachLang.Language == LANG_SCALA {
pathstring = append(pathstring, LANG_SCALA)
pathstring = append(pathstring, dataServers.OS)
sourcePath = filepath.Join(leSourcePath, LANG_SCALA, dataServers.OS, dataInstaller.InstallerSource)
destinationPath = strings.Join(pathstring, serverPathSeparator)
installShPath = filepath.Join(leSourcePath, LANG_SCALA, dataServers.OS, "install.sh")
uninstallShPath = filepath.Join(leSourcePath, LANG_SCALA, dataServers.OS, "uninstall.sh")
}
installShdestPath := strings.Join(append(pathstring, "install.sh"), serverPathSeparator)
uninstallShdestPath := strings.Join(append(pathstring, "uninstall.sh"), serverPathSeparator)
// installFilePath := strings.Join(append(pathstring, dataInstaller.InstallerSource), serverPathSeparator)
err = sshSetting.SshCopyByPath(sourcePath, destinationPath)
if err != nil {
return outputCmd, err
}
err = sshSetting.SshCopyByPath(installShPath, destinationPath)
if err != nil {
return outputCmd, err
}
err = sshSetting.SshCopyByPath(uninstallShPath, destinationPath)
if err != nil {
return outputCmd, err
}
//sed -i 's/^M//' install.sh
cmdSedInstall := fmt.Sprintf("sed -i 's/\r//g' %s", installShdestPath)
_, err = sshSetting.GetOutputCommandSsh(cmdSedInstall)
if err != nil {
return outputCmd, err
}
//sed -i 's/^M//' uninstall.sh
cmdSedUninstall := fmt.Sprintf("sed -i 's/\r//g' %s", uninstallShdestPath)
_, err = sshSetting.GetOutputCommandSsh(cmdSedUninstall)
if err != nil {
return outputCmd, err
}
// // chmod +x install.sh
cmdChmodCliInstall := fmt.Sprintf("chmod +x %s", installShdestPath)
_, err = sshSetting.GetOutputCommandSsh(cmdChmodCliInstall)
if err != nil {
return outputCmd, err
}
// // chmod +x uninstall.sh
cmdChmodCliUninstall := fmt.Sprintf("chmod +x %s", uninstallShdestPath)
_, err = sshSetting.GetOutputCommandSsh(cmdChmodCliUninstall)
if err != nil {
return outputCmd, err
}
// // sh install.sh installFilePath DESTINSTALL_PATH projectpath
cmdShCli := fmt.Sprintf("bash %s %s", uninstallShdestPath, DESTINSTALL_PATH)
outputCmd, err = sshSetting.RunCommandSshAsMap(cmdShCli)
if err != nil {
return outputCmd, err
}
fmt.Println(" :: : ", outputCmd[0].Output)
// targetLang.IsInstalled = true
// dataServers.InstalledLang = append(dataServers.InstalledLang, targetLang)
// colonycore.Save(dataServers)
}
}
}
}
return outputCmd, nil
}