如何将telnet控制台日志重定向到文件linux [英] How to redirect the telnet console logs to a file linux

查看:1073
本文介绍了如何将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

参考文献:探索期望

这篇关于如何将telnet控制台日志重定向到文件linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆