Created
September 19, 2016 16:20
-
-
Save jessedearing/a6a49c6fda99892e3e800662e5a7199a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db, err := sql.Open("mysql", user+":"+password+"@tcp("+host+":3306)/information_schema") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer db.Close() | |
hostWithPort := getHost(db) | |
if hostWithPort == nil { | |
log.Println("Could not find query with that ID") | |
return | |
} | |
hostAndPort := strings.Split(hostWithPort, ":") | |
host, port := hostAndPort[0], hostAndPort[1] | |
log.Printf("Host: %s Port: %s\n", host, port) | |
func getHost(db *sql.DB) string { | |
result, err := db.Query("select HOST from processlist where ID = ?", *pid) | |
if err != nil { | |
log.Panic(err) | |
} | |
defer result.Close() | |
var host string | |
for result.Next() { | |
result.Scan(&host) | |
} | |
return host | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment