From 6eac7d989bb28cb1e1ea201000842d4deca8626c Mon Sep 17 00:00:00 2001 From: cuisongliu Date: Tue, 24 Mar 2020 13:30:34 +0800 Subject: [PATCH] fix(v1.0): fix replace --- pkg/sshutil/ssh.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/sshutil/ssh.go b/pkg/sshutil/ssh.go index f5eb65d..98804c3 100644 --- a/pkg/sshutil/ssh.go +++ b/pkg/sshutil/ssh.go @@ -1,8 +1,11 @@ package sshutil -import "github.com/wonderivan/logger" +import ( + "github.com/wonderivan/logger" + "strings" +) -//Cmd is +//Cmd is in host exec cmd func (ss *SSH) Cmd(host string, cmd string) []byte { logger.Info("[%s]exec cmd is : %s", host, cmd) session, err := ss.Connect(host) @@ -29,9 +32,12 @@ func (ss *SSH) Cmd(host string, cmd string) []byte { return b } -func (ss *SSH) CmdToString(host, cmd string) string { +//CmdToString is in host exec cmd and replace to spilt str +func (ss *SSH) CmdToString(host, cmd, spilt string) string { data := ss.Cmd(host, cmd) if data != nil { + str := string(data) + str = strings.ReplaceAll(str, "\r\n", spilt) return string(data) } return ""