Skip to content

Instantly share code, notes, and snippets.

@monkeybutter
Created September 18, 2016 13:33
Show Gist options
  • Select an option

  • Save monkeybutter/f1c9e6eedf1af315be892ed715c32022 to your computer and use it in GitHub Desktop.

Select an option

Save monkeybutter/f1c9e6eedf1af315be892ed715c32022 to your computer and use it in GitHub Desktop.
package main
import (
"os/exec"
"encoding/json"
"os"
"bufio"
"fmt"
"strings"
)
func getHostMap() (map[string]string, error) {
hostMap := make(map[string]string)
f, err := os.Open(os.Getenv("PBS_NODEFILE"))
if err != nil {
return nil, err
}
r := bufio.NewReader(f)
s, e := r.ReadString('\n')
for e == nil {
host := strings.Fields(s)[0]
out, err := exec.Command("getent", "hosts", host).Output()
if err != nil {
return nil, err
}
hostMap[host] = strings.Fields(string(out))[0]
s, e = r.ReadString('\n')
}
return hostMap, nil
}
func main() {
hostMap, _ := getHostMap()
hosts := make([]string, len(hostMap))
idx := 0
for _, value := range hostMap {
hosts[idx] = value
idx++
}
json, _ := json.Marshal(dict)
hostMap := make(map[string]string)
for host, ip := range dict {
fmt.Println(host, ip)
//out, _ := exec.Command("ssh", fmt.Sprintf("prl900@%s", ip), "nohup", "/g/data1/sp9/prl900/stampede/server/benchmark_server", "&").Output()
//fmt.Println(string(out))
}
fmt.Println(dict)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment