GoAccess not recognizing --keep-db-files and others - goaccess

I have installed goaccess-1.0.2 along with the ncurses and the optional dependencies provided by goaccess man page on my Ubuntu 16.04 OS.
I am successfully able to parse logs with the following command: goaccess -f access.log -a. I am able to create logs into an html report with the following command goaccess -f access.log -a -o report.html.
I am not able to successfully parse data into real time html output with the following command goaccess -f access.log -o report.html --real-time-html. However, it does start to parse, but at some point it freezes. So I assume the data is to large for memory.
So I wanted to learn how to parse data to disk. I used the following command goaccess -f access.log --keep-db-files. I received the following feedback: goaccess: unrecognized option '--keep-db-files'
I thought maybe I missed dependencies, but I checked back through the goaccess man page and it doesn't seem that I am.

However, it does start to parse, but at some point it freezes. So I assume the data is to large for memory.
If you are successfully parsing the same log with goaccess -f access.log -a, then using --real-time-html shouldn't make any difference. Check your memory usage with top or take a look at dmesg.
I used the following command goaccess -f access.log --keep-db-files. I received the following feedback: goaccess: unrecognized option '--keep-db-files'
You need to compile GoAccess with btree support. To do this, you need to install TokyoCabinet and then build goaccess from source:
$ sudo apt-get install libtokyocabinet-dev
$ curl http://tar.goaccess.io/goaccess-1.0.2.tar.gz | tar xvz
$ cd goaccess-1.0.2/
$ ./configure --enable-utf8 --enable-geoip --enable-tcb=btree
$ make
$ sudo make install

Related

searching for a solution to write log file pg restore

I get an conflict error with -d and -f together, do you have a solution ?
pg_restore -d mydb -h myhost --clean --verbose c:\dba\Manager\tk\Tasks\import-tk-21aug2022\budget-app-sara-21.8_updated_withdata -f c:\dba\manager\tk\restore-tk-21aug2022.log
-f is not for a log file. -f says instead of restoring the dump to a database, write a SQL script which will do the restore.
-d says to restore the dump to the given database.
They say to do two different things, so they conflict. You have to decide which one you want to do.
See the pg_restore docs.

How can I grep a count of available updates from yum check-updates

I want to check if updates are available, and if so, perform some steps before I install the updates. I run yum check-updates to see a list of updates available for installed packages, but I'd like to grep this and get a count that I can use for some logic in a bash script. So ideally, I would like to grep that output of check-updates and return 0 if there are no updates, or if five updates are available then I would like the grep to return 5.
How can I grep this to return the count?
I like a simpler approach.
"yum -q" reduces the output from yum so it only displays a list of packages. Combine this with "wc -l" to count the number of lines output.
So to get a count of packages requiring updates I would run
sudo yum -q check-update | wc -l
Are you aware of grep -c? I've just created some nonsense file, giving following result:
Prompt> grep "AA" test.txt
1A01 TCCTTGAAAG
TCAACAAGAA
TCGCAAA
TTTAAAGTCGT
GGCGGAATCAATAC
GATGGAATATGCGCC
If I use grep -c, this is the result:
Prompt> grep -c "AA" test.txt
6
In case this does not answer your question completely, please edit your question and add some more information, just to show what you are looking for.
Also, please be aware that adding | wc -l behind every UNIX command reads the amount of results of that command.
This combination of awk and grep gives the count of available updates for installed packages:
yum check-updates | awk 'p;/^$/{p=1}' | grep -c "\."
This was based on the info in How to get just a list of yum updates
The -q for quiet is great but you may also want to grep out any blank lines and also the trailing Loaded plugins message. This works nicely for an accurate count:
yum check-update -q|egrep -v "Loaded plugins: langpacks, product-id, subscription-manager|^$"|wc -l

I need help parsing HTML with grep [duplicate]

It works ok as a single tool:
curl "someURL"
curl -o - "someURL"
but it doesn't work in a pipeline:
curl "someURL" | tr -d '\n'
curl -o - "someURL" | tr -d '\n'
it returns:
(23) Failed writing body
What is the problem with piping the cURL output? How to buffer the whole cURL output and then handle it?
This happens when a piped program (e.g. grep) closes the read pipe before the previous program is finished writing the whole page.
In curl "url" | grep -qs foo, as soon as grep has what it wants it will close the read stream from curl. cURL doesn't expect this and emits the "Failed writing body" error.
A workaround is to pipe the stream through an intermediary program that always reads the whole page before feeding it to the next program.
E.g.
curl "url" | tac | tac | grep -qs foo
tac is a simple Unix program that reads the entire input page and reverses the line order (hence we run it twice). Because it has to read the whole input to find the last line, it will not output anything to grep until cURL is finished. Grep will still close the read stream when it has what it's looking for, but it will only affect tac, which doesn't emit an error.
For completeness and future searches:
It's a matter of how cURL manages the buffer, the buffer disables the output stream with the -N option.
Example:
curl -s -N "URL" | grep -q Welcome
Another possibility, if using the -o (output file) option - the destination directory does not exist.
eg. if you have -o /tmp/download/abc.txt and /tmp/download does not exist.
Hence, ensure any required directories are created/exist beforehand, use the --create-dirs option as well as -o if necessary
The server ran out of disk space, in my case.
Check for it with df -k .
I was alerted to the lack of disk space when I tried piping through tac twice, as described in one of the other answers: https://stackoverflow.com/a/28879552/336694. It showed me the error message write error: No space left on device.
You can do this instead of using -o option:
curl [url] > [file]
So it was a problem of encoding. Iconv solves the problem
curl 'http://www.multitran.ru/c/m.exe?CL=1&s=hello&l1=1' | iconv -f windows-1251 | tr -dc '[:print:]' | ...
If you are trying something similar like source <( curl -sS $url ) and getting the (23) Failed writing body error, it is because sourcing a process substitution doesn't work in bash 3.2 (the default for macOS).
Instead, you can use this workaround.
source /dev/stdin <<<"$( curl -sS $url )"
Trying the command with sudo worked for me. For example:
sudo curl -O -k 'https url here'
note: -O (this is capital o, not zero) & -k for https url.
I had the same error but from different reason. In my case I had (tmpfs) partition with only 1GB space and I was downloading big file which finally filled all memory on that partition and I got the same error as you.
I encountered the same problem when doing:
curl -L https://packagecloud.io/golang-migrate/migrate/gpgkey | apt-key add -
The above query needs to be executed using root privileges.
Writing it in following way solved the issue for me:
curl -L https://packagecloud.io/golang-migrate/migrate/gpgkey | sudo apt-key add -
If you write sudo before curl, you will get the Failed writing body error.
For me, it was permission issue. Docker run is called with a user profile but root is the user inside the container. The solution was to make curl write to /tmp since that has write permission for all users , not just root.
I used the -o option.
-o /tmp/file_to_download
In my case, I was doing:
curl <blabla> | jq | grep <blibli>
With jq . it worked: curl <blabla> | jq . | grep <blibli>
I encountered this error message while trying to install varnish cache on ubuntu. The google search landed me here for the error (23) Failed writing body, hence posting a solution that worked for me.
The bug is encountered while running the command as root curl -L https://packagecloud.io/varnishcache/varnish5/gpgkey | apt-key add -
the solution is to run apt-key add as non root
curl -L https://packagecloud.io/varnishcache/varnish5/gpgkey | apt-key add -
The explanation here by #Kaworu is great: https://stackoverflow.com/a/28879552/198219
This happens when a piped program (e.g. grep) closes the read pipe before the previous program is finished writing the whole page. cURL doesn't expect this and emits the "Failed writing body" error.
A workaround is to pipe the stream through an intermediary program that always reads the whole page before feeding it to the next program.
I believe the more correct implementation would be to use sponge, as already suggested by #nisetama in the comments:
curl "url" | sponge | grep -qs foo
I got this error trying to use jq when I didn't have jq installed. So... make sure jq is installed if you're trying to use it.
In Bash and zsh (and perhaps other shells), you can use process substitution (Bash/zsh) to create a file on the fly, and then use that as input to the next process in the pipeline chain.
For example, I was trying to parse JSON output from cURL using jq and less, but was getting the Failed writing body error.
# Note: this does NOT work
curl https://gitlab.com/api/v4/projects/ | jq | less
When I rewrote it using process substitution, it worked!
# this works!
jq "" <(curl https://gitlab.com/api/v4/projects/) | less
Note: jq uses its 2nd argument to specify an input file
Bonus: If you're using jq like me and want to keep the colorized output in less, use the following command line instead:
jq -C "" <(curl https://gitlab.com/api/v4/projects/) | less -r
(Thanks to Kowaru for their explanation of why Failed writing body was occurring. However, their solution of using tac twice didn't work for me. I also wanted to find a solution that would scale better for large files and tries to avoid the other issues noted as comments to that answer.)
I was getting curl: (23) Failed writing body . Later I noticed that I did not had sufficient space for downloading an rpm package via curl and thats the reason I was getting issue. I freed up some space and issue for resolved.
I had the same question because of my own typo mistake:
# fails because of reasons mentioned above
curl -I -fail https://www.google.com | echo $?
curl: (23) Failed writing body
# success
curl -I -fail https://www.google.com || echo $?
I added flag -s and it did the job. eg: curl -o- -s https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Command executed in busybox shell script gives no output

I boot my computer with initramfs that I have generated with gentoo genkernel. I now tweak and update initramfs filesystem and kernel by hand for more flexibility.
I tried to update busybox as the newer version has more functionalities, from
v1.20.2 generated by genkernel to v1.25.1 in my main gentoo system.
I get the following problem that I am unable to solve
#!/bin/busybox sh
blkid -U 4b714b37-3590-48e9-8866-465d9e6726f2e
gives no output while
#!/bin/sh
blkid -U 4b714b37-3590-48e9-8866-465d9e6726f2e
gives /dev/sda4 as expected.
Thank you very much for your suggestions.
It seems that busybox blkid does not recognize -U option and do not output any error message. I solved my problem invoking blkid without any argument and parsing the output manually.
blkid | grep 4b714b37-3590-48e9-8866-465d9e6726f2e | cut -d ":" -f1

How can I use aria2 with pacman?

I want to make an alias for zsh to download packages by aria2 and install them by pacman,
I don't want to use aria2c by adding xfercommand to pacman.conf because of 2 things:
First my internet connection's speed is low and I don't want pacman go lock for some hours,
Second xfercommand doesn't support multi link downloads.
First off, I use this command to download or upgrade and update by pacman:
sudo pacman -Sp [Package] > ~/Documents/.install&& sudo aria2c -c -x16 -x16 -m16 -k1M -j10 -i ~/Documents/.install -d /var/cache/pacman/pkg
But I don't know how to make it alias in zsh?
Install aria2, then edit /etc/pacman.conf by adding the following line to the [options] section:
XferCommand = /usr/bin/aria2c --allow-overwrite=true --continue=true --file-allocation=none --log-level=error --max-tries=2 --max-connection-per-server=2 --max-file-not-found=5 --min-split-size=5M --no-conf --remote-time=true --summary-interval=60 --timeout=5 --dir=/ --out %o %u
Taking from the aria2 arch wiki, you don't need the intermediary install file, just use the flag -i -. I also had to add sudo to the aria command. Looks like this:
pacman -Sp [package] | sudo aria2c -d /var/cache/pacman/pkg/ -i -
I have an aria2 config, so all other options are there.
From what I've seen, if you use aria2 in the XferCommand, it wouldn't do multiple downloads, just use aria2 one link at a time.
As for using a function, try
mypacman() {
pacman -Sp $1 | sudo aria2c -d /var/cache/pacman/pkg/ -i -
}
The $1 indicates the first thing after the function call will be placed in this place.
Use it like mypacman [package].
Note: It seems the next version of pacman will do parallel downloads out of the box :)
http://allanmcrae.com/
But I won't risk using it right now...

Resources