How do I exit tail --follow on ERROR or FATAL log level [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I tail -f the log file of one of my services, but I would like to automatically stop my tail process once my logger has printed any content starting with OR containing ERROR or FATAL.
How can I achieve this?

To terminate tail -f immediately after the output has a line containing ERROR or FATAL, try:
tail -f file.log | awk '{print} /ERROR|FATAL/{exit}'
Example
$ cat file.log
abc
def
ghi
ERROR
jkl
mno
pqr
$ tail -f file.log | awk '{print} /ERROR|FATAL/{exit}'
abc
def
ghi
ERROR

Related

What is the equivalent of "grep -e pattern1 -e pattern2 <file> " in Solaris? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
What is the equivalent of grep -e pattern1 -e pattern2 "$file" in Solaris?
In Linux it works fine. but in Solaris, i got "grep: illegal option -- e
Usage: grep -hblcnsviw pattern file . . ." error.
Can anyone help please?
Instead of:
# GNU grep only
grep -e pattern1 -e pattern2 file
...you can use:
# POSIX-compliant
grep -e 'pattern1
pattern2' file

Last users connected to the system [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Hello how to display the last sessions from all users connected to the system in linux (but that are not connected any more) ?
Using this last with awk:
last | awk 'NF>7 && !/still logged in/ && !seen[$1]++'
last -F | grep -v "still logged in" | cut -d " " -f1
The command for that is called last :-)
Please try below command:
last | awk 'NF>7 && !/still logged in/ && !seen[$1]++' | cut -d " " -f1

Count number of files within a directory in Linux? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
To count the number of files in a directory, I typically use
ls directory | wc -l
But is there another command that doesn't use wc ?
this is one:
ls -l . | egrep -c '^-'
Note:
ls -1 | wc -l
Which means:
ls: list files in dir
-1: (that's a ONE) only one entry per line. Change it to -1a if you want hidden files too
|: pipe output onto...
wc: "wordcount"
-l: count lines.

linux/ unix command for checking specific logs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
how can I extract a log based on specific time frame? Let's say issue started between 4pm to 5pm, how can I get that specific log between those times? I can use less or cat or grep but it would not give me the details of the error, sample command:
grep "2013-08-26 16:00:00" sample.log
what is the more precise Linux/ Unix command that can do the trick?
For viewing ERROR log messages between 16:00:00 and 17:00:00 use:
grep -nP '2013-08-15 16:.+ERROR' sample.log | less
If you have multiline messages in log you can use -A n and -B n params to add for each output string n lines after or before:
3 lines before and after each line:
grep -A 3 -B 3 -nP '2013-08-15 16:.+ERROR' sample.log | less
Shorthand for the same:
grep -3 -nP '2013-08-15 16:.+ERROR' sample.log | less
If you know that issue happened between 4 and 5 pm, you can use this:
grep "2013-08-26 16:" sample.log | less
If you need some lines around that issue, add option -N to grep (context of N lines), something like that:
grep -3 "2013-08-26 16:" sample.log | less
If you know that your event contained some specific word, you can filter it more using one more grep:
grep -3 "2013-08-26 16:" sample.log | grep somethingelse

Is \d not supported by grep's basic expressions? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
Improve this question
This does not generate any output. How come?
$ echo 'this 1 2 3' | grep '\d\+'
But these do:
$ echo 'this 1 2 3' | grep '\s\+'
this 1 2 3
$ echo 'this 1 2 3' | grep '\w\+'
this 1 2 3
As specified in POSIX, grep uses basic regular expressions, but \d is part of a Perl-compatible regular expression (PCRE).
If you are using GNU grep, you can use the -P option, to allow use of PCRE regular expressions. Otherwise you can use the POSIX-specified [[:digit:]] character class in place of \d.
echo 1 | grep -P '\d'
# output: 1
echo 1 | grep '[[:digit:]]'
# output: 1
Try this $ echo 'this 1 2 3' | grep '[0-9]\+'

Resources