Golang Geteuid Examples, os.Geteuid Golang Examples - HotExamples
For checking the operation of batches run by root. Equivalent to whoami command
whoami.go
package main
import (
"fmt"
"os"
)
func main() {
if os.Geteuid() != 0 {
fmt.Println("Must be run as root")
os.Exit(1)
}
os.Exit(0)
}
//General user execution
$ go run whoami.go
Must be run as root
exit status 1
//root execution
# go run whoami.go
# echo $?
0
Recommended Posts