예제 #1
0
func selfUpdate() {
	baseFileContent, err := kmgHttp.UrlGetContent("http://kmgtools.qiniudn.com/v1/installKmg.bash?v=" + kmgRand.MustCryptoRandToAlphaNum(16))
	kmgConsole.ExitOnErr(err)

	baseFilePath := "/tmp/installKmg.bash"
	kmgFile.MustDeleteFile(baseFilePath)
	kmgFile.MustAppendFile(baseFilePath, baseFileContent)
	kmgCmd.MustRunInBash(baseFilePath)
}
예제 #2
0
파일: Ip_forward.go 프로젝트: keysonZZZ/kmg
// 证实可用
func SetIpForwardOn() {
	if !kmgPlatform.IsLinux() {
		panic("[SetIpForwardOn] only support linux now")
	}
	kmgFile.MustWriteFile("/proc/sys/net/ipv4/ip_forward", []byte("1"))
	// 已经证实,多次写入不会出现任何问题.
	// TODO 正确解析/etc/sysctl.conf 如果后面又加一条 = 0 估计就挂了.
	if !bytes.Contains(kmgFile.MustReadFile("/etc/sysctl.conf"), []byte("\nnet.ipv4.ip_forward = 1")) {
		kmgFile.MustAppendFile("/etc/sysctl.conf", []byte("\nnet.ipv4.ip_forward = 1"))
	}
}
예제 #3
0
파일: cmd.go 프로젝트: keysonZZZ/kmg
func MustRpcSshCmd(ip string, cmd ...string) []byte {
	if len(cmd) == 0 {
		return []byte{}
	}
	if ip == "" {
		return []byte{}
	}
	cmdCombine := strings.Join(cmd, "&&")
	out, err := kmgCmd.CmdString("ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no root@" + ip + " " + cmdCombine).RunAndReturnOutput()
	logPath := "/tmp/rpcSshCmd-" + ip
	kmgFile.MustAppendFile(logPath, []byte(strings.Join([]string{cmdCombine, kmgTime.DefaultFormat(time.Now())}, "\n")))
	kmgFile.MustAppendFile(logPath, out)
	if err != nil {
		//		_, ok := err.(*exec.ExitError)
		//		if ok {
		//			return out
		//		}
		kmgFile.MustAppendFile(logPath, []byte(err.Error()))
		panic(err)
	}
	return out
}
예제 #4
0
파일: sshCopyId.go 프로젝트: keysonZZZ/kmg
func RunCmdWithPassword(cmd, password string) {
	cmdTpl := `#!/usr/bin/expect -f
spawn %s
expect "assword:"
send "%s\r"
interact`
	cmd = fmt.Sprintf(cmdTpl, cmd, password)
	tmpName := kmgRand.MustCryptoRandToReadableAlphaNum(5)
	tmpPath := "/tmp/" + tmpName
	kmgFile.MustAppendFile(tmpPath, []byte(cmd))
	defer kmgFile.MustDelete(tmpPath)
	os.Setenv("HOME", kmgSys.GetCurrentUserHomeDir())
	kmgCmd.CmdSlice([]string{tmpPath}).MustStdioRun()
}
예제 #5
0
파일: main.go 프로젝트: keysonZZZ/kmg
func log(msg string) {
	wMsg := fmt.Sprintf("%s %s\n", time.Now(), msg)
	os.Stdout.WriteString(wMsg)
	kmgFile.MustAppendFile(logFilePath, []byte(wMsg))
}