MCPcopy Create free account
hub / github.com/appleboy/easyssh-proxy / Run

Method Run

easyssh.go:447–481  ·  view source on GitHub ↗

Run command on remote machine and returns its stdout as a string

(command string, timeout ...time.Duration)

Source from the content-addressed store, hash-verified

445
446// Run command on remote machine and returns its stdout as a string
447func (ssh_conf *MakeConfig) Run(command string, timeout ...time.Duration) (outStr string, errStr string, isTimeout bool, err error) {
448 stdoutChan, stderrChan, doneChan, errChan, err := ssh_conf.Stream(command, timeout...)
449 if err != nil {
450 // Check if the error is from a proxy dial timeout
451 if errors.Is(err, ErrProxyDialTimeout) {
452 isTimeout = true
453 }
454 return outStr, errStr, isTimeout, err
455 }
456 // read from the output channel until the done signal is passed
457loop:
458 for {
459 select {
460 case isTimeout = <-doneChan:
461 break loop
462 case outline, ok := <-stdoutChan:
463 if !ok {
464 stdoutChan = nil
465 }
466 if outline != "" {
467 outStr += outline + "\n"
468 }
469 case errline, ok := <-stderrChan:
470 if !ok {
471 stderrChan = nil
472 }
473 if errline != "" {
474 errStr += errline + "\n"
475 }
476 case err = <-errChan:
477 }
478 }
479 // return the concatenation of all signals from the output channel
480 return outStr, errStr, isTimeout, err
481}
482
483// WriteFile reads size bytes from the reader and writes them to a file on the remote machine
484func (ssh_conf *MakeConfig) WriteFile(reader io.Reader, size int64, etargetFile string) error {

Callers 13

TestRunCommandFunction · 0.95
TestWrongRawKeyFunction · 0.95
TestExitCodeFunction · 0.95
TestSSHWithPassphraseFunction · 0.95
TestRootAccountFunction · 0.95
TestSudoCommandFunction · 0.95
TestCommandTimeoutFunction · 0.95
mainFunction · 0.95

Calls 1

StreamMethod · 0.95

Tested by 11

TestRunCommandFunction · 0.76
TestWrongRawKeyFunction · 0.76
TestExitCodeFunction · 0.76
TestSSHWithPassphraseFunction · 0.76
TestRootAccountFunction · 0.76
TestSudoCommandFunction · 0.76
TestCommandTimeoutFunction · 0.76