|
|
@ -178,24 +178,24 @@ func LoginSimple(host string, user string, passwd string, prikeyPath string, por
|
|
|
|
return Login(info)
|
|
|
|
return Login(info)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) ShellWait(cmd string) (string, string, error) {
|
|
|
|
func (s *StarShell) ShellWait(cmd string) (string, string, error) {
|
|
|
|
var outc, errc string = " ", " "
|
|
|
|
var outc, errc string = " ", " "
|
|
|
|
this.Clear()
|
|
|
|
s.Clear()
|
|
|
|
defer this.Clear()
|
|
|
|
defer s.Clear()
|
|
|
|
echo := "echo b7Y85R56TUY6R5UTb612"
|
|
|
|
echo := "echo b7Y85R56TUY6R5UTb612"
|
|
|
|
err := this.WriteCommand(cmd)
|
|
|
|
err := s.WriteCommand(cmd)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", "", err
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
time.Sleep(time.Millisecond * 20)
|
|
|
|
time.Sleep(time.Millisecond * 20)
|
|
|
|
err = this.WriteCommand(echo)
|
|
|
|
err = s.WriteCommand(echo)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", "", err
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
time.Sleep(time.Millisecond * 120)
|
|
|
|
time.Sleep(time.Millisecond * 120)
|
|
|
|
outs := string(this.outbyte)
|
|
|
|
outs := string(s.outbyte)
|
|
|
|
errs := string(this.errbyte)
|
|
|
|
errs := string(s.errbyte)
|
|
|
|
outs = strings.TrimSpace(strings.ReplaceAll(outs, "\r\n", "\n"))
|
|
|
|
outs = strings.TrimSpace(strings.ReplaceAll(outs, "\r\n", "\n"))
|
|
|
|
errs = strings.TrimSpace(strings.ReplaceAll(errs, "\r\n", "\n"))
|
|
|
|
errs = strings.TrimSpace(strings.ReplaceAll(errs, "\r\n", "\n"))
|
|
|
|
if len(outs) >= len(cmd+"\n"+echo) && outs[0:len(cmd+"\n"+echo)] == cmd+"\n"+echo {
|
|
|
|
if len(outs) >= len(cmd+"\n"+echo) && outs[0:len(cmd+"\n"+echo)] == cmd+"\n"+echo {
|
|
|
@ -206,7 +206,7 @@ func (this *StarShell) ShellWait(cmd string) (string, string, error) {
|
|
|
|
if len(errs) >= len(cmd) && errs[0:len(cmd)] == cmd {
|
|
|
|
if len(errs) >= len(cmd) && errs[0:len(cmd)] == cmd {
|
|
|
|
errs = errs[len(cmd):]
|
|
|
|
errs = errs[len(cmd):]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if this.UseWaitDefault {
|
|
|
|
if s.UseWaitDefault {
|
|
|
|
if strings.Index(string(outs), "b7Y85R56TUY6R5UTb612") >= 0 {
|
|
|
|
if strings.Index(string(outs), "b7Y85R56TUY6R5UTb612") >= 0 {
|
|
|
|
list := strings.Split(string(outs), "\n")
|
|
|
|
list := strings.Split(string(outs), "\n")
|
|
|
|
for _, v := range list {
|
|
|
|
for _, v := range list {
|
|
|
@ -226,20 +226,20 @@ func (this *StarShell) ShellWait(cmd string) (string, string, error) {
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if this.Keyword != "" {
|
|
|
|
if s.Keyword != "" {
|
|
|
|
if strings.Index(string(outs), this.Keyword) >= 0 {
|
|
|
|
if strings.Index(string(outs), s.Keyword) >= 0 {
|
|
|
|
list := strings.Split(string(outs), "\n")
|
|
|
|
list := strings.Split(string(outs), "\n")
|
|
|
|
for _, v := range list {
|
|
|
|
for _, v := range list {
|
|
|
|
if strings.Index(v, this.Keyword) < 0 && strings.Index(v, "b7Y85R56TUY6R5UTb612") < 0 {
|
|
|
|
if strings.Index(v, s.Keyword) < 0 && strings.Index(v, "b7Y85R56TUY6R5UTb612") < 0 {
|
|
|
|
outc += v + "\n"
|
|
|
|
outc += v + "\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if strings.Index(string(errs), this.Keyword) >= 0 {
|
|
|
|
if strings.Index(string(errs), s.Keyword) >= 0 {
|
|
|
|
list := strings.Split(string(errs), "\n")
|
|
|
|
list := strings.Split(string(errs), "\n")
|
|
|
|
for _, v := range list {
|
|
|
|
for _, v := range list {
|
|
|
|
if strings.Index(v, this.Keyword) < 0 && strings.Index(v, "b7Y85R56TUY6R5UTb612") < 0 {
|
|
|
|
if strings.Index(v, s.Keyword) < 0 && strings.Index(v, "b7Y85R56TUY6R5UTb612") < 0 {
|
|
|
|
errc += v + "\n"
|
|
|
|
errc += v + "\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -247,23 +247,23 @@ func (this *StarShell) ShellWait(cmd string) (string, string, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.TrimColor(strings.TrimSpace(outc)), this.TrimColor(strings.TrimSpace(errc)), err
|
|
|
|
return s.TrimColor(strings.TrimSpace(outc)), s.TrimColor(strings.TrimSpace(errc)), err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) Close() error {
|
|
|
|
func (s *StarShell) Close() error {
|
|
|
|
return this.Session.Close()
|
|
|
|
return s.Session.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) SwitchNoColor(is bool) {
|
|
|
|
func (s *StarShell) SwitchNoColor(is bool) {
|
|
|
|
this.iscolor = is
|
|
|
|
s.iscolor = is
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) SwitchEcho(is bool) {
|
|
|
|
func (s *StarShell) SwitchEcho(is bool) {
|
|
|
|
this.isecho = is
|
|
|
|
s.isecho = is
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) TrimColor(str string) string {
|
|
|
|
func (s *StarShell) TrimColor(str string) string {
|
|
|
|
if this.iscolor {
|
|
|
|
if s.iscolor {
|
|
|
|
return SedColor(str)
|
|
|
|
return SedColor(str)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str
|
|
|
|
return str
|
|
|
@ -272,42 +272,42 @@ func (this *StarShell) TrimColor(str string) string {
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
本函数控制是否在本地屏幕上打印远程Shell的输出内容[true|false]
|
|
|
|
本函数控制是否在本地屏幕上打印远程Shell的输出内容[true|false]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
func (this *StarShell) SwitchPrint(run bool) {
|
|
|
|
func (s *StarShell) SwitchPrint(run bool) {
|
|
|
|
this.isprint = run
|
|
|
|
s.isprint = run
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
本函数控制是否立即处理远程Shell输出每一行内容[true|false]
|
|
|
|
本函数控制是否立即处理远程Shell输出每一行内容[true|false]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
func (this *StarShell) SwitchFunc(run bool) {
|
|
|
|
func (s *StarShell) SwitchFunc(run bool) {
|
|
|
|
this.isfuncs = run
|
|
|
|
s.isfuncs = run
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) SetFunc(funcs func(string)) {
|
|
|
|
func (s *StarShell) SetFunc(funcs func(string)) {
|
|
|
|
this.funcs = funcs
|
|
|
|
s.funcs = funcs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) Clear() {
|
|
|
|
func (s *StarShell) Clear() {
|
|
|
|
defer this.rw.Unlock()
|
|
|
|
defer s.rw.Unlock()
|
|
|
|
this.rw.Lock()
|
|
|
|
s.rw.Lock()
|
|
|
|
this.outbyte = []byte{}
|
|
|
|
s.outbyte = []byte{}
|
|
|
|
this.errbyte = []byte{}
|
|
|
|
s.errbyte = []byte{}
|
|
|
|
time.Sleep(time.Millisecond * 15)
|
|
|
|
time.Sleep(time.Millisecond * 15)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) ShellClear(cmd string, sleep int) (string, string, error) {
|
|
|
|
func (s *StarShell) ShellClear(cmd string, sleep int) (string, string, error) {
|
|
|
|
defer this.Clear()
|
|
|
|
defer s.Clear()
|
|
|
|
this.Clear()
|
|
|
|
s.Clear()
|
|
|
|
return this.Shell(cmd, sleep)
|
|
|
|
return s.Shell(cmd, sleep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) Shell(cmd string, sleep int) (string, string, error) {
|
|
|
|
func (s *StarShell) Shell(cmd string, sleep int) (string, string, error) {
|
|
|
|
if err := this.WriteCommand(cmd); err != nil {
|
|
|
|
if err := s.WriteCommand(cmd); err != nil {
|
|
|
|
return "", "", err
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tmp1, tmp2, err := this.GetResult(sleep)
|
|
|
|
tmp1, tmp2, err := s.GetResult(sleep)
|
|
|
|
tmps := this.TrimColor(strings.TrimSpace(string(tmp1)))
|
|
|
|
tmps := s.TrimColor(strings.TrimSpace(string(tmp1)))
|
|
|
|
if this.isecho {
|
|
|
|
if s.isecho {
|
|
|
|
n := len(strings.Split(cmd, "\n"))
|
|
|
|
n := len(strings.Split(cmd, "\n"))
|
|
|
|
if n == 1 {
|
|
|
|
if n == 1 {
|
|
|
|
list := strings.SplitN(tmps, "\n", 2)
|
|
|
|
list := strings.SplitN(tmps, "\n", 2)
|
|
|
@ -334,50 +334,50 @@ func (this *StarShell) Shell(cmd string, sleep int) (string, string, error) {
|
|
|
|
tmps = tmps[0 : len(tmps)-1]
|
|
|
|
tmps = tmps[0 : len(tmps)-1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tmps, this.TrimColor(strings.TrimSpace(string(tmp2))), err
|
|
|
|
return tmps, s.TrimColor(strings.TrimSpace(string(tmp2))), err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) GetResult(sleep int) ([]byte, []byte, error) {
|
|
|
|
func (s *StarShell) GetResult(sleep int) ([]byte, []byte, error) {
|
|
|
|
if this.errors != nil {
|
|
|
|
if s.errors != nil {
|
|
|
|
this.Session.Close()
|
|
|
|
s.Session.Close()
|
|
|
|
return this.outbyte, this.errbyte, this.errors
|
|
|
|
return s.outbyte, s.errbyte, s.errors
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if sleep > 0 {
|
|
|
|
if sleep > 0 {
|
|
|
|
time.Sleep(time.Millisecond * time.Duration(sleep))
|
|
|
|
time.Sleep(time.Millisecond * time.Duration(sleep))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.outbyte, this.errbyte, nil
|
|
|
|
return s.outbyte, s.errbyte, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) WriteCommand(cmd string) error {
|
|
|
|
func (s *StarShell) WriteCommand(cmd string) error {
|
|
|
|
return this.Write([]byte(cmd + "\n"))
|
|
|
|
return s.Write([]byte(cmd + "\n"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) Write(bstr []byte) error {
|
|
|
|
func (s *StarShell) Write(bstr []byte) error {
|
|
|
|
if this.errors != nil {
|
|
|
|
if s.errors != nil {
|
|
|
|
this.Session.Close()
|
|
|
|
s.Session.Close()
|
|
|
|
return this.errors
|
|
|
|
return s.errors
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_, err := this.in.Write(bstr)
|
|
|
|
_, err := s.in.Write(bstr)
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) gohub() {
|
|
|
|
func (s *StarShell) gohub() {
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
var cache []byte
|
|
|
|
var cache []byte
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
read, err := this.er.ReadByte()
|
|
|
|
read, err := s.er.ReadByte()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
this.errors = err
|
|
|
|
s.errors = err
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.errbyte = append(this.errbyte, read)
|
|
|
|
s.errbyte = append(s.errbyte, read)
|
|
|
|
if this.isprint {
|
|
|
|
if s.isprint {
|
|
|
|
fmt.Print(string([]byte{read}))
|
|
|
|
fmt.Print(string([]byte{read}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cache = append(cache, read)
|
|
|
|
cache = append(cache, read)
|
|
|
|
if read == '\n' {
|
|
|
|
if read == '\n' {
|
|
|
|
if this.isfuncs {
|
|
|
|
if s.isfuncs {
|
|
|
|
go this.funcs(this.TrimColor(strings.TrimSpace(string(cache))))
|
|
|
|
go s.funcs(s.TrimColor(strings.TrimSpace(string(cache))))
|
|
|
|
cache = []byte{}
|
|
|
|
cache = []byte{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -385,47 +385,47 @@ func (this *StarShell) gohub() {
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
var cache []byte
|
|
|
|
var cache []byte
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
read, err := this.out.ReadByte()
|
|
|
|
read, err := s.out.ReadByte()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
this.errors = err
|
|
|
|
s.errors = err
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.rw.Lock()
|
|
|
|
s.rw.Lock()
|
|
|
|
this.outbyte = append(this.outbyte, read)
|
|
|
|
s.outbyte = append(s.outbyte, read)
|
|
|
|
cache = append(cache, read)
|
|
|
|
cache = append(cache, read)
|
|
|
|
this.rw.Unlock()
|
|
|
|
s.rw.Unlock()
|
|
|
|
if read == '\n' {
|
|
|
|
if read == '\n' {
|
|
|
|
if this.isfuncs {
|
|
|
|
if s.isfuncs {
|
|
|
|
go this.funcs(strings.TrimSpace(string(cache)))
|
|
|
|
go s.funcs(strings.TrimSpace(string(cache)))
|
|
|
|
cache = []byte{}
|
|
|
|
cache = []byte{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if this.isprint {
|
|
|
|
if s.isprint {
|
|
|
|
fmt.Print(string([]byte{read}))
|
|
|
|
fmt.Print(string([]byte{read}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarShell) GetUid() string {
|
|
|
|
func (s *StarShell) GetUid() string {
|
|
|
|
res, _, _ := this.ShellWait(`id | grep -oP "(?<=uid\=)\d+"`)
|
|
|
|
res, _, _ := s.ShellWait(`id | grep -oP "(?<=uid\=)\d+"`)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (this *StarShell) GetGid() string {
|
|
|
|
func (s *StarShell) GetGid() string {
|
|
|
|
res, _, _ := this.ShellWait(`id | grep -oP "(?<=gid\=)\d+"`)
|
|
|
|
res, _, _ := s.ShellWait(`id | grep -oP "(?<=gid\=)\d+"`)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (this *StarShell) GetUser() string {
|
|
|
|
func (s *StarShell) GetUser() string {
|
|
|
|
res, _, _ := this.ShellWait(`id | grep -oP "(?<=\().*?(?=\))" | head -n 1`)
|
|
|
|
res, _, _ := s.ShellWait(`id | grep -oP "(?<=\().*?(?=\))" | head -n 1`)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (this *StarShell) GetGroup() string {
|
|
|
|
func (s *StarShell) GetGroup() string {
|
|
|
|
res, _, _ := this.ShellWait(`id | grep -oP "(?<=\().*?(?=\))" | head -n 2 | tail -n 1`)
|
|
|
|
res, _, _ := s.ShellWait(`id | grep -oP "(?<=\().*?(?=\))" | head -n 2 | tail -n 1`)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarSSH) NewShell() (shell *StarShell, err error) {
|
|
|
|
func (s *StarSSH) NewShell() (shell *StarShell, err error) {
|
|
|
|
shell = new(StarShell)
|
|
|
|
shell = new(StarShell)
|
|
|
|
shell.Session, err = this.NewSession()
|
|
|
|
shell.Session, err = s.NewSession()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -449,19 +449,19 @@ func (this *StarSSH) NewShell() (shell *StarShell, err error) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarSSH) Close() error {
|
|
|
|
func (s *StarSSH) Close() error {
|
|
|
|
if this.online {
|
|
|
|
if s.online {
|
|
|
|
return this.Client.Close()
|
|
|
|
return s.Client.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarSSH) NewSession() (*ssh.Session, error) {
|
|
|
|
func (s *StarSSH) NewSession() (*ssh.Session, error) {
|
|
|
|
return NewSession(this.Client)
|
|
|
|
return NewSession(s.Client)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarSSH) ShellOne(cmd string) (string, error) {
|
|
|
|
func (s *StarSSH) ShellOne(cmd string) (string, error) {
|
|
|
|
newsess, err := this.NewSession()
|
|
|
|
newsess, err := s.NewSession()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -470,8 +470,8 @@ func (this *StarSSH) ShellOne(cmd string) (string, error) {
|
|
|
|
return strings.TrimSpace(string(data)), err
|
|
|
|
return strings.TrimSpace(string(data)), err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarSSH) Exists(filepath string) bool {
|
|
|
|
func (s *StarSSH) Exists(filepath string) bool {
|
|
|
|
res, _ := this.ShellOne(`echo 1 && [ ! -e "` + filepath + `" ] && echo 2`)
|
|
|
|
res, _ := s.ShellOne(`echo 1 && [ ! -e "` + filepath + `" ] && echo 2`)
|
|
|
|
if res == "1" {
|
|
|
|
if res == "1" {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -479,25 +479,25 @@ func (this *StarSSH) Exists(filepath string) bool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarSSH) GetUid() string {
|
|
|
|
func (s *StarSSH) GetUid() string {
|
|
|
|
res, _ := this.ShellOne(`id | grep -oP "(?<=uid\=)\d+"`)
|
|
|
|
res, _ := s.ShellOne(`id | grep -oP "(?<=uid\=)\d+"`)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (this *StarSSH) GetGid() string {
|
|
|
|
func (s *StarSSH) GetGid() string {
|
|
|
|
res, _ := this.ShellOne(`id | grep -oP "(?<=gid\=)\d+"`)
|
|
|
|
res, _ := s.ShellOne(`id | grep -oP "(?<=gid\=)\d+"`)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (this *StarSSH) GetUser() string {
|
|
|
|
func (s *StarSSH) GetUser() string {
|
|
|
|
res, _ := this.ShellOne(`id | grep -oP "(?<=\().*?(?=\))" | head -n 1`)
|
|
|
|
res, _ := s.ShellOne(`id | grep -oP "(?<=\().*?(?=\))" | head -n 1`)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (this *StarSSH) GetGroup() string {
|
|
|
|
func (s *StarSSH) GetGroup() string {
|
|
|
|
res, _ := this.ShellOne(`id | grep -oP "(?<=\().*?(?=\))" | head -n 2 | tail -n 1`)
|
|
|
|
res, _ := s.ShellOne(`id | grep -oP "(?<=\().*?(?=\))" | head -n 2 | tail -n 1`)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
return strings.TrimSpace(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarSSH) IsFile(filepath string) bool {
|
|
|
|
func (s *StarSSH) IsFile(filepath string) bool {
|
|
|
|
res, _ := this.ShellOne(`echo 1 && [ ! -f "` + filepath + `" ] && echo 2`)
|
|
|
|
res, _ := s.ShellOne(`echo 1 && [ ! -f "` + filepath + `" ] && echo 2`)
|
|
|
|
if res == "1" {
|
|
|
|
if res == "1" {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -505,8 +505,8 @@ func (this *StarSSH) IsFile(filepath string) bool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarSSH) IsFolder(filepath string) bool {
|
|
|
|
func (s *StarSSH) IsFolder(filepath string) bool {
|
|
|
|
res, _ := this.ShellOne(`echo 1 && [ ! -d "` + filepath + `" ] && echo 2`)
|
|
|
|
res, _ := s.ShellOne(`echo 1 && [ ! -d "` + filepath + `" ] && echo 2`)
|
|
|
|
if res == "1" {
|
|
|
|
if res == "1" {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -514,8 +514,8 @@ func (this *StarSSH) IsFolder(filepath string) bool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarSSH) ShellOneShowScreen(cmd string) (string, error) {
|
|
|
|
func (s *StarSSH) ShellOneShowScreen(cmd string) (string, error) {
|
|
|
|
newsess, err := this.NewSession()
|
|
|
|
newsess, err := s.NewSession()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -559,8 +559,8 @@ func (this *StarSSH) ShellOneShowScreen(cmd string) (string, error) {
|
|
|
|
return strings.TrimSpace(string(bytes)), err
|
|
|
|
return strings.TrimSpace(string(bytes)), err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *StarSSH) ShellOneToFunc(cmd string, callback func(string)) (string, error) {
|
|
|
|
func (s *StarSSH) ShellOneToFunc(cmd string, callback func(string)) (string, error) {
|
|
|
|
newsess, err := this.NewSession()
|
|
|
|
newsess, err := s.NewSession()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|