如何将telnet控制台日志重定向到文件linux
我想将telnet控制台日志重定向到Linux中的文件.
I want to redirect the telnet console logs to a file in linux.
例如:
telnet $someIp > someFile
#ls
#exit
我希望控制台日志保存在文件名"someFile"中.我正在使用tcl
自动执行此操作.到目前为止,我正在tcl
中执行spawn telnet $someIp
.
I want the console logs to get 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.
可以做到吗?
期望有一种编程方式来启动和停止记录(或logginig).给定文件名参数,log_file
命令将打开文件并开始对其进行记录.如果日志文件已经打开,则首先关闭旧文件.
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.
记录是通过附加到文件来完成的,因此,如果文件中以前存储了任何内容,则它将保留.要重新开始,请使用-noappend
标志.
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.
您可以通过在不需要时关闭日志记录来节省空间.可以通过不带任何参数的log_file
调用来实现.例如,以下片段开始记录,执行一些I/O,停止记录,执行更多I/O,然后再次开始记录.
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
默认情况下,log_file
仅记录用户看到的内容.如果已调用log_user
命令以禁止生成的程序的输出,则log_file不会记录禁止的输出,因为用户也看不到它. log_file
可以使用-a
标志(对于所有输出")记录抑制的输出.
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
和以前一样,可以通过发出不带参数的log_file来禁用此日志记录.要仅返回用户看到的日志,请在不使用-a的情况下调用log_file.
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
参考文献:探索期望