简体   繁体   English

如何将 telnet 控制台日志重定向到文件 Linux

[英]How to redirect the telnet console logs to a file Linux

I want to redirect the telnet console logs to a file in Linux.我想将 telnet 控制台日志重定向到 Linux 中的文件。

For example:例如:

telnet $someIp > someFile
#ls
#exit

I want the console logs to be saved in the filename someFile .我希望控制台日志保存在文件名someFile I am using tcl for automating this.我正在使用tcl来实现自动化。 As of now, I am doing spawn telnet $someIp in tcl .截至目前,我正在tcl执行spawn telnet $someIp

This will not capture the console logs and save it to a file.这不会捕获控制台日志并将其保存到文件中。

Can this be done?这能做到吗?

您可以使用tee命令来完成:

telnet $someIp | tee -a -i someFile

Expect has a programmatic means to start and stop recording (or logginig). Expect 具有启动和停止记录(或登录)的程序化方式。 Given a file name argument, the log_file command opens the file and begins recording to it.给定文件名参数, log_file命令打开文件并开始记录。 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.要重新开始,请使用-noappend标志。

You can save space by turning off logging when it is not necessary.您可以通过在不需要时关闭日志记录来节省空间。 This is accomplished by calling log_file with no arguments.这是通过不带参数调用log_file来实现的。 For example, the following fragment starts recording, does some I/O, stops recording, does some more I/O, and then starts recording again.例如,以下片段开始录制,执行一些 I/O,停止录制,执行更多 I/O,然后再次开始录制。

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.默认情况下, log_file只记录用户看到的内容。 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.如果已调用log_user命令来抑制生成的程序的输出,则 log_file 不会记录被抑制的输出,因为用户也看不到它。 The log_file can record the suppressed output by using the -a flag (for "all output"). log_file可以通过使用-a标志(用于“所有输出”)来记录被抑制的输出。

log_file -a log

As before, this logging can be disabled by issuing log_file with no arguments.和以前一样,可以通过发出不带参数的 log_file 来禁用此日志记录。 To return to logging just what the user sees, invoke log_file without the -a.要返回仅记录用户看到的内容,请调用不带 -a 的 log_file。

log_file -a log
expect . . . ; send . . .
log_file log

Reference : Exploring Expect参考:探索Expect

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM