Exemple #1
0
func listKeys(addr string, prefix string) {
	println("Listing keys (hosts = "+addr, ", prefix = '"+prefix+"')")
	t, err := telnet.Dial("tcp", addr)
	checkErr(err)
	t.SetUnixWriteMode(true)

	slabs := getSlabs(t)
	keys := findKeys(t, slabs, prefix)
	for i := range keys {
		log.Printf("key: %s", keys[i])
	}
}
Exemple #2
0
func deleteKeys(addr string, prefix string) {
	println("Deleting keys (hosts = "+addr, ", prefix = '"+prefix+"')")
	t, err := telnet.Dial("tcp", addr)
	checkErr(err)
	t.SetUnixWriteMode(true)

	slabs := getSlabs(t)
	keys := findKeys(t, slabs, prefix)

	mc, e1 := memcache.New(addr)
	checkErr(e1)

	for i := range keys {
		key := keys[i]
		log.Printf("Removing key: %s", key)

		e2 := mc.Delete(key)
		checkErr(e2)
	}
}
Exemple #3
0
func main() {
	if len(os.Args) != 5 {
		log.Printf("Usage: %s {unix|cisco} HOST:PORT USER PASSWD", os.Args[0])
		return
	}
	typ, dst, user, passwd := os.Args[1], os.Args[2], os.Args[3], os.Args[4]

	t, err := telnet.Dial("tcp", dst)
	checkErr(err)
	t.SetUnixWriteMode(true)

	var data []byte
	switch typ {
	case "unix":
		expect(t, "login: "******"ssword: ")
		sendln(t, passwd)
		expect(t, "$")
		sendln(t, "ls -l")
		data, err = t.ReadBytes('$')
	case "cisco":
		expect(t, "name: ")
		sendln(t, user)
		expect(t, "ssword: ")
		sendln(t, passwd)
		expect(t, ">")
		sendln(t, "sh ver")
		data, err = t.ReadBytes('>')
	default:
		log.Fatalln("bad host type: " + typ)
	}
	checkErr(err)
	os.Stdout.Write(data)
	os.Stdout.WriteString("\n")
}