3

I want to capture the output of my expect script in a file.txt.

#!/usr/bin/expect -f

match_max 10000
set timeout 120
eval spawn ssh 10.0.0.0
set prompt ":|#|\\\$"
interact -o -nobuffer -re $prompt return
send "password\r"
expect ">"
send "sh cdp neighbors detail\r\r                              "
expect ">"
send "\n"
sleep 5

This is what I have, he reads out my cdp neighbors detail from a switch. But now I want to push this output in a file, in my directory. So I can automate doing commands on a switch, and get the output. The script works completely but I can't find enough information to read the output from an expect script.

Thanks in advance!

Omnomnom

Omnomnom
  • 111
  • 2
  • 2
  • 11

2 Answers2

6

You can make use of log_file.

log_file switch.log;# Logging it into the file 'switch.log'

Just add that before the line from where you want to capture the logging. Have a look at here for more information.

Community
  • 1
  • 1
Dinesh
  • 16,014
  • 23
  • 80
  • 122
4

Found it, very easy:

./expectscript > output.txt 2>&1
Omnomnom
  • 111
  • 2
  • 2
  • 11