Reputation: 5862
I am just simply trying to run gvm-setup
to configure 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.
If I run the following:
gvm-setup | tee ~/.openvas_install.txt
then it sends the whole output to the file, as expected. 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.
How can I go about this? 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:
gvm-setup | tail -n 2 output_file.txt
Here's an example of the 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.
Upvotes: 0
Views: 985
Reputation: 41753
If you need both the log file and the tail output then you should use 2 separate commands line this
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. 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
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
gvm-setup | tee ~/.openvas_install.txt | tail -n 2
Upvotes: 2