How to redirect the telnet console logs to a file Linux
Asked Answered
N

2

11

I want to redirect the telnet console logs to a file in Linux.

For example:

telnet $someIp > someFile
#ls
#exit

I want the console logs to be saved in the filename someFile. I am using tcl for automating this. As of now, I am doing spawn telnet $someIp in tcl.

This will not capture the console logs and save it to a file.

Can this be done?

Nalda answered 3/2, 2015 at 6:41 Comment(0)
F
4

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

Froze answered 3/2, 2015 at 6:53 Comment(0)
C
28

You can do it by using the tee command:

telnet $someIp | tee -a -i someFile
Choric answered 3/2, 2015 at 6:45 Comment(4)
Thanks.It worked. But i could see some junk characters getting displayed like ^[[1;34m. Any idea how to remove this?Nalda
@Nalda Those are just codes for rendering colors. Refer to unix.stackexchange.com/questions/58982/… on how to get rid of themDiandrous
Exactly what I needed - damn telnet in 2020 and those ISP router/modems who still use telnet and not SSH :)Stokeontrent
this is useful, I'm going to backup memcached dataNel
F
4

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

Froze answered 3/2, 2015 at 6:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.