Documentation
¶
Overview ¶
Example (LocalRun) ¶
package main
import (
"context"
"github.com/viant/gosh"
"github.com/viant/gosh/runner/local"
)
func main() {
srv, err := gosh.New(context.Background(), local.New())
if err != nil {
return
}
_, _, err = srv.Run(context.Background(), "cd /etc")
output, _, err := srv.Run(context.Background(), "ls -l")
println(output)
}
Example (RemoteRun) ¶
package main
import (
"bytes"
"context"
"github.com/viant/afs"
"github.com/viant/gosh"
"github.com/viant/gosh/runner/ssh"
"github.com/viant/scy/cred"
"os"
"path"
)
func main() {
host := "localhost"
privateKeyBytes := getKeyLocation(host)
if privateKeyBytes == nil {
return
}
sshCred := cred.SSH{
PrivateKeyPayload: privateKeyBytes,
Basic: cred.Basic{
Username: os.Getenv("USER"),
},
}
clientConfig, err := sshCred.Config(context.Background())
if err != nil {
panic(err)
}
srv, err := gosh.New(context.Background(), ssh.New(host+":22", clientConfig))
if err != nil {
return
}
_, _, err = srv.Run(context.Background(), "cd /etc")
output, _, err := srv.Run(context.Background(), "ls -l")
println(output)
}
func getKeyLocation(host string) []byte {
ctx := context.Background()
fs := afs.New()
knowHostLocation := path.Join(os.Getenv("HOME"), ".ssh/known_hosts")
knownHosts, _ := fs.DownloadWithURL(ctx, knowHostLocation)
if len(knownHosts) == 0 || !bytes.Contains(knownHosts, []byte(host)) {
return nil
}
keyLocation := path.Join(os.Getenv("HOME"), ".ssh/id_rsa")
exists, _ := fs.Exists(ctx, keyLocation)
if !exists {
return nil
}
keyBytes, _ := fs.DownloadWithURL(ctx, keyLocation)
return keyBytes
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HardwareInfo ¶
type HardwareInfo struct {
Hardware string // Hardware details
Architecture string // Full architecture name
Arch string // Architecture abbreviation, typically from uname -m
Version string // Hardware version
}
HardwareInfo represents hardware details
type OSInfo ¶
type OSInfo struct {
System string // Operating system type
Name string // Name of the OS
DistributorID string // ID of the distributor (from lsb_release -a)
Description string // Full description of the OS (from lsb_release -a)
Release string // OS release number (from lsb_release -a)
Codename string // OS release codename (from lsb_release -a)
}
OSInfo represents operating system details
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents a shell service
func (*Service) HardwareInfo ¶
func (s *Service) HardwareInfo() *HardwareInfo
HardwareInfo represents hardware information
Click to show internal directories.
Click to hide internal directories.