title: How to have Expect script output to file
body: <p>I need to gather some statistics from a network switch and would like to use an expect script to output the data to a file. I would like to run this script as a cron job and have the data appended to the file when it is run. Following is the working code I have so far, I just do not know how to get the output to a file. Any help is greatly appreciated.</p>
  
  <pre><code> #!/bin/bash
   #get mac-address count
   /usr/bin/expect -f -&lt;&lt;EOD
  
   spawn ssh user@192.168.1.100
   sleep 2
  
   #Catch the password prompt and send supplied password
   expect {
   "*word:" {send "password\r"}
   }
   sleep 1
  
   #Get into enabled mode
   expect {
   "*&gt;" {send "system-view\r"}
   }
   sleep 1
  
   expect {
   "*]" {send "display mac-address count\r"}
   }
   sleep 1
  
   expect { 
   "*]" {send "quit\r"}
   }
   sleep  1
  
   expect {
   "*&gt;" {send  "quit\r"}
   }
   sleep 1
  
   expect eof
   EOD
  </code></pre>