How to redirect the telnet console logs to a file Linux
You can do it by using the tee
command:
telnet $someIp | tee -a -i someFile
Expect has a programmatic means to start and stop recording (or logginig). Given a file name argument, the log_file
command opens the file and begins recording to it. If a log file is already open, the old file is closed first.
Recording is done by appending to the file, so if anything has previously been stored in the file, it remains. To start over, use the -noappend
flag.
You can save space by turning off logging when it is not necessary. This is accomplished by calling log_file
with no arguments. For example, the following fragment starts recording, does some I/O, stops recording, does some more I/O, and then starts recording again.
expect . . . ; send
# start recording
log_file telnetlog
expect . . . ; send
# stop recording
log_file
expect . . . ; send
# start recording
log_file telnetlog
expect . . . ; send
By default, log_file
records only what the user sees. If the log_user
command has been invoked to suppress output from a spawned program, the suppressed output is not recorded by log_file since the user is not seeing it either. The log_file
can record the suppressed output by using the -a
flag (for "all output").
log_file -a log
As before, this logging can be disabled by issuing log_file with no arguments. To return to logging just what the user sees, invoke log_file without the -a.
log_file -a log
expect . . . ; send . . .
log_file log
Reference : Exploring Expect