title: Talking to Cisco equipment using go ssh library
body: <p>I'm trying to implement monitoring various Cisco ASR parameters doing ssh to router and using show commands to get results. Here is part of the workflow (error handling omitted):
  </p>
  
  <pre><code>client, err := ssh.Dial("tcp", "172.16.32.95:22", config)
  session, err := client.NewSession()
  sshOut, err := session.StdoutPipe()
  sshIn, err := session.StdinPipe()
  err := session.RequestPty("xterm", 80, 40, modes)
  err := session.Shell()
  </code></pre>
  
  <p>At this point I can write to <code>sshIn</code> and read from <code>sshOut</code>.
  Since Cisco's (and other vendor's) routers don't support exec'ing commands (correct me if I'm wrong) all I can do is to pass commands to shell and read input until I find command prompt.</p>
  
  <p>Ok. Here is part I use to skip initial router greetings before the first command prompt:</p>
  
  <pre><code>buf := make([]byte, 1000)
  n, err := sshOut.Read(buf) //this reads the ssh terminal welcome message
  loadStr := ""
  if err == nil {
      loadStr = string(buf[:n])
  }
  for (err == nil) &amp;&amp; (!strings.Contains(loadStr, "[local]")) {
      n, err = sshOut.Read(buf)
      loadStr += string(buf[:n])
  }
  fmt.Println(loadStr)
  </code></pre>
  
  <p>which yields:</p>
  
  <pre><code>Last login: Tue Jan 14 17:29:06 -0500 2014 on pts/1 from 172.16.35.101.
  Cisco Systems SSI
  [local]ewag# 
  </code></pre>
  
  <p>To run command I write to <code>sshIn</code>:</p>
  
  <pre><code>if _, err := sshIn.Write([]byte("show clock\r")); err != nil {
      panic("Failed to run: " + err.Error())
  }
  </code></pre>
  
  <p>And read response the same way I read initial greeting, which yields (with greetings):</p>
  
  <pre><code>Last login: Tue Jan 14 18:06:14 -0500 2014 on pts/2 from 10.7.7.14.
  Cisco Systems SSI
  [local]ewag# 
  show clock
  Tuesday January 14 18:09:19 EST 2014
  [local]ewag# 
  </code></pre>
  
  <p>Still everything ok. But when I try to send somewhat longer command, f.e.:</p>
  
  <pre><code>if _, err := sshIn.Write([]byte("show session progress ipsg-service ipsg-gprs-svc\r")); err != nil {
      panic("Failed to run: " + err.Error())
  }
  </code></pre>
  
  <p>Output breaks:</p>
  
  <pre><code>Last login: Tue Jan 14 18:09:19 -0500 2014 on pts/2 from 10.7.7.14.
  Cisco Systems SSI
  [local]ewag# 
  show session progress ipsg
  -service ipsg-gprs-svc
  Unknown command - "ipsg-service", unrecognized keyword
  [local]ewag# 
  </code></pre>
  
  <p>The command I've sent got split at some point, but output for command result is passed correctly without splits.</p>
  
  <p>So question is how this split can be fixed? For now I'm out of ideas.
  Thanks for attention!</p>