title: Expect Script - Starting logging from a certain point, and stop at a certain point
body: <p>Hope you're all well!</p>
  
  <p>I've recently begun putting together a little utility for a few our of network engineers to use. It's function is to retrieve circuit information which is then parsed and outputted in a nice format. Of course, part of this involves an SSH connection to the box required and running the command to generate the desired output.</p>
  
  <p>Here's the script I've currently got. It works fine, runs the desired command, sends a few blank spaces to prompt the system to display more circuits, and then finishes off by exiting. All of this is being logged into a file with a name identical to the box's hostname. Great.</p>
  
  <p>However my issue is apparent when I read the file produced and see that it includes a ton of data, including the command I ran and unnecessary stats provided on connection. I'm only looking for the logging to begin when I issue the command, and for it to cut off afterwards. As I'm not familiar with expect, I'd really appreciate any guidance.</p>
  
  <p><em>PS. Apologies if I've done anything stupid; I'm pretty new to the language itself and the support out there isn't that great.</em></p>
  
  <p>Thanks.</p>
  
  <pre><code>set ip [lindex $argv 0]
  set hostname [lindex $argv 1]
  set timeout 10
  set user ""
  set password ""
  
  # Spawning the ssh session
  spawn ssh $ip -l $user
  
  # Awaiting prompt for password
  expect "$user@$ip's password:"
  sleep 1;
  # Awaiting prompt
  send "$password\n"
  sleep 2
  log_file -noappend $hostname;
  send "terminal length 0\n"
  sleep 1
  send "show int desc\n"
  sleep 5
  send "exit\n"
  interact
  exit
  </code></pre>