2021-10-16 15:39:54 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SSHConfig struct {
|
|
|
|
signer ssh.Signer
|
|
|
|
config *ssh.ClientConfig
|
|
|
|
client *ssh.Client
|
|
|
|
logged bool
|
|
|
|
name string
|
|
|
|
snapshot []Snapshot
|
|
|
|
}
|
|
|
|
|
2021-11-14 08:58:47 +01:00
|
|
|
func (s *SSHConfig) exec(cmd string) (b *bytes.Buffer, err error) {
|
2021-10-16 15:39:54 +02:00
|
|
|
if *debugFlag {
|
|
|
|
log.Printf("SSHConfig.exec : %s : Start %s", s.name, cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
session, err := s.client.NewSession()
|
|
|
|
if err != nil {
|
|
|
|
if *debugFlag {
|
|
|
|
log.Printf("SSHConfig.exec : %s : client().NewSession(%s) : %s", s.name, cmd, err)
|
|
|
|
}
|
2021-11-14 08:58:47 +01:00
|
|
|
return
|
2021-10-16 15:39:54 +02:00
|
|
|
}
|
|
|
|
|
2021-11-14 08:58:47 +01:00
|
|
|
var buf bytes.Buffer
|
|
|
|
b = &buf
|
|
|
|
session.Stdout = b
|
|
|
|
|
2021-10-16 15:39:54 +02:00
|
|
|
err = session.Run("TZ=\"" + cfg.Timezone + "\" " + cmd)
|
|
|
|
if err != nil {
|
|
|
|
if *debugFlag {
|
|
|
|
log.Printf("SSHConfig.exec : session(%s).Run(%s) : %s", s.name, cmd, err)
|
|
|
|
}
|
2021-11-14 08:58:47 +01:00
|
|
|
return
|
2021-10-16 15:39:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
session.Close()
|
|
|
|
|
2021-11-14 08:58:47 +01:00
|
|
|
return
|
2021-10-16 15:39:54 +02:00
|
|
|
}
|