Example #1
0
func execLine(session *ssh.Session, cmd string) {
	out, err := session.CombinedOutput(cmd)
	if err != nil {
		// panic(err)
		log.Fatal(err.Error())
	}
	fmt.Println(string(out))
}
Example #2
0
// RunCommandWithOutput runs a shell command in a vagrant node and returns it's
// exit status and output
func (n *VagrantNode) RunCommandWithOutput(cmd string) (string, error) {
	var (
		s   *ssh.Session
		err error
	)

	if s, err = n.client.NewSession(); err != nil {
		return "", err
	}
	defer s.Close()

	output, err := s.CombinedOutput(newCmdStrWithSource(cmd))
	return string(output), err
}
Example #3
0
// Executes a command on an SSH session struct, return an error if there is one
func executeCommand(cmd string, session *ssh.Session) (string, error) {
	//Runs CombinedOutput, which takes cmd and returns stderr and stdout of the command
	out, err := session.CombinedOutput(cmd)
	if err != nil {
		return "", err
	}

	// Convert our output to a string
	tmpOut := string(out)
	tmpOut = strings.Replace(tmpOut, "\n", "<br>", -1)

	// Return a string version of our result
	return tmpOut, nil
}
Example #4
0
func (client *clientSSH) runCommand(cmd *sshCommand) ([]byte, error) {
	var session *ssh.Session
	var err error

	if session, err = client.newSession(); err != nil {
		return []byte{}, err
	}
	defer session.Close()

	if err = client.prepareCommand(session, cmd); err != nil {
		return []byte{}, err
	}

	return session.CombinedOutput(cmd.command)
}