2024-04-29 21:00:04 +02:00
|
|
|
package sshsession
|
|
|
|
|
|
2024-05-09 18:16:37 +02:00
|
|
|
import (
|
|
|
|
|
"io"
|
2024-04-29 21:00:04 +02:00
|
|
|
|
2024-05-09 18:16:37 +02:00
|
|
|
"golang.org/x/crypto/ssh"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Run(client *ssh.Client, cmd string, stdin io.Reader) ([]byte, error) {
|
2024-04-29 21:00:04 +02:00
|
|
|
sess, err := client.NewSession()
|
2024-05-09 18:16:37 +02:00
|
|
|
|
2024-04-29 21:00:04 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2025-05-04 00:40:35 +02:00
|
|
|
defer func() { _ = sess.Close() }()
|
2024-05-09 18:16:37 +02:00
|
|
|
|
|
|
|
|
if stdin != nil {
|
|
|
|
|
sess.Stdin = stdin
|
|
|
|
|
}
|
2024-04-29 21:00:04 +02:00
|
|
|
return sess.CombinedOutput(cmd)
|
|
|
|
|
}
|