My apologies in advance if this comes across scatterbrained. I am a little fizzled out and am going to take a break on this.
ipmitool -I lanplus -H ipmiHost -U ipmiUser -f ipmiPWFile sdr elist all | grep -c -i "cpu.*temp"
I have been less successful using the os.exec package like so (or similar to)
commandText := []string{"bash", "-c", "/usr/local/bin/ipmitool -I lanplus -H", ipmiHost, "-U", ipmiUser, "-f", ipmiPWFile, "sdr elist all | grep -c -i \"cpu.*temp\""}
numCPUCmd := exec.Command(commandText[0], commandText[1:]...)
numCPUBytes, err := numCPUCmd.Output()
This is likely for many reasons,
When you are using shell commands that need expansion, pipes, etc, and you are passing it to /bin/bash -c, the entire command after the -c needs to be a string. In your example, you start with part of the command as a string and then start passing more items in the slice. Just string format your command first and pass it as the 3rd item in your slice.
cmd := fmt.Sprintf("/usr/local/bin/ipmitool -I lanplus -H %s -U %s -f %s sdr elist all | grep -c -i 'cpu.*temp'", ipmiHost, ipmiUser, ipmiPWFile)
but I am more focused on the next step here. I have since looked back and am attempting to use the standard library but am now stuck on how to do the equivalent of the above with, or similar to, the below:
cpuNum := bytes.Count(ipmiOutput, []byte("cpu.([]+)temp"))
Take a look at counting the results of a regular expression match:
Thank you for any guidance. I may go back to using the exec commands and piping one StdOut to another's StdIn.