hostname check basically working

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-12-16 09:36:40 -06:00
parent a33eca708a
commit 1532d885e0
2 changed files with 48 additions and 1 deletions

View File

@ -42,9 +42,19 @@ func getHostname() {
// On Linux, /etc/hosts, /etc/hostname
// and domainname and hostname
func goodHostname(h string) bool {
hostname := shell.Cat("/etc/hostname")
hostname := shell.Chomp(shell.Cat("/etc/hostname"))
log.Println("hostname =", hostname)
hs := run("hostname -s")
dn := run("domainname")
log.Println("hostname short =", hs, "domainname =", dn)
tmp := hs + "." + dn
if (hostname == tmp) {
log.Println("hostname seems to be good", hostname)
return true
}
return false
}

37
run.go Normal file
View File

@ -0,0 +1,37 @@
package main
import (
"bytes"
"fmt"
"strings"
"os/exec"
"git.wit.org/wit/shell"
)
func run(s string) string {
cmdArgs := strings.Fields(s)
// Define the command you want to run
// cmd := exec.Command(cmdArgs)
cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
// Create a buffer to capture the output
var out bytes.Buffer
// Set the output of the command to the buffer
cmd.Stdout = &out
// Run the command
err := cmd.Run()
if err != nil {
fmt.Println("Error running command:", err)
return ""
}
tmp := shell.Chomp(out.String())
// Output the results
fmt.Println("Command Output:", tmp)
return tmp
}