[英]Tail only the output of a command
I am just simply trying to run gvm-setup
to configure OpenVAS.我只是想运行gvm-setup
来配置 OpenVAS。 Since the installation is 100% unattended and doesn't require any user input, I am simply just trying to tail the last 2 lines to a file.由于安装是 100% 无人值守的,并且不需要任何用户输入,我只是想将最后两行添加到文件中。
If I run the following:如果我运行以下命令:
gvm-setup | tee ~/.openvas_install.txt
then it sends the whole output to the file, as expected.然后它按预期将整个 output 发送到文件。 This file is a whole 12MB large and I only need the last 2 lines of it to capture the password that gets presented to the user at the end of the configuration process.这个文件有 12MB 大,我只需要它的最后 2 行来捕获在配置过程结束时呈现给用户的密码。
How can I go about this?我怎么能 go 关于这个? I realize that I can just simply tail
the large 12MB file as an alternative, but I'm wondering if there's something like this that would work:我意识到我可以简单地tail
12MB 的大文件作为替代方案,但我想知道是否有这样的东西可以工作:
gvm-setup | tail -n 2 output_file.txt
Here's an example of the output:以下是 output 的示例:
[*] Checking Default scanner
08b69003-5fc2-4037-a479-93b440211c73 OpenVAS /var/run/ospd/ospd.sock 0 OpenVAS Default
[+] Done
[*] Please note the password for the admin user
[*] User created with password 'd6ae47e5-26d0-4a85-a0ce-99b9cb3fd09d'.
and I just simply need to capture the randomly generated password.我只需要捕获随机生成的密码。
If you need both the log file and the tail output then you should use 2 separate commands line this如果您需要日志文件和尾部 output 那么您应该使用 2 个单独的命令行
gvm-setup >~/.openvas_install.txt
tail -n 2 ~/.openvas_install.txt
Because when passing a file to tail
then it knows that it can get file size and seek to the end of the file immediately.因为当将文件传递给tail
时,它知道它可以获取文件大小并立即查找文件末尾。 If you pipe the output to tail
then it has to actually consume that huge amount of data before receiving the end of pipe and prints out the data如果您将 pipe output tail
,那么它必须在接收到 pipe 的末尾之前实际消耗大量数据并打印出数据
Of course tee
also works because it saves the output to file and to the next command in the pipe, but it'll be far less efficient当然tee
也有效,因为它将 output 保存到文件和 pipe 中的下一个命令,但效率会低得多
gvm-setup | tee ~/.openvas_install.txt | tail -n 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.