I'd like to grep the build log to count the number of compiler warnings. Is it possible to run a command on the build log from this or previous step?
TeamCity Enterprise 2022.04.4 (build 108763)
You could try to save compiler's output to a file and then grep it. For example
make 2>&1 | tee make.log
grep -o 'WARN' make.log | wc -l
In that case tee prints command output to both stdout and file
Related
On OSX I'm trying to create a tarball of a directory and on the fly encrypt
it with gpg and keeps the output of the tar messages in a log file for
later analysis.
While the tar+gpg on the fly it's pretty easy
tar zcvf - foo | gpg -e -r foo#bar.com -o foo.tgz.gpg
so far I'm failing to log the output of tar (and maybe the gpg one in
case) to a log file.
I tried several combination of
tar | gpg | tee
tar | gpg 2>&1 >(tee)
tar | gpg > file.log
any help here?
Cheers
Davide
2> file.log should achieve it.
If you want to tee the stderr stream and also keep it going to the original destination, you can achieve that with
2> >(tee file.log >&2)
In your example:
tar zcvf - foo 2> >(tee file.log >&2) | gpg -e -r foo#bar.com -o foo.tgz.gpg
Your attempts don't succeed because the piping (|) only forwards stdout of the previous command to the stdin of the current one. The current command (gpg) doesn't have access to the stderr of the previous command (tar). That stderr has already gone to its destination (your terminal, most likely).
2> >(command ) pipes (quite literally >() create an unnamed, OS-level pipe underneath) stderr to stdin of command. Since command is a child process, its stderr (#2) descriptor will point to the same file as the stderr of the parent process.
The problem is that when using 2> at the end of the line, you redirect only the second command (gpg) stderr. If you want (as it seems) to redirect the tar command stderr, you should add 2> logfile before the pipe, like this:
tar zcvf - foo 2> tar.log | gpg -e -r foo#bar.com -o foo.tgz.gpg
I am implementing a shell script and I want to analyse the output shown by hwclock -r (--show) command which displays the RTC time and date.
To do that I tried things like: hwclock -r | grep -v "grep" | grep "error" > /dev/null
to see if an error happened while reading RTC registers.
The problem is that output is only and always forwarded to console. I tried to forward output to a file then analyse its content and I also tried to use tee -a command to direct output to both console and a file, but with no success.
Is there a solution to that or an explanation to what is happening with hwclock -r command.
In advance Thank you.
I just solved it by forwarding error messages to a file then make the analysis.
hwclock -r 2> file.txt; grep -v "grep" | grep "error" > /dev/null will do the job.
You omitted file.txt in the first grep.
If you just want to check for "error", with a not too old bash this will also do, in a shorter way:
hwclock -r |& grep error >/dev/null
I am trying to redirect output of a command to a file. The command I am using (zypper) downloads packages from the internet. The command I am using is
zypper -x -n in geany >> log.txt
The command gradually prints output to the console. The problem I am facing is that the above command writes the command output all at once after the command finishes executing. How do I redirect the bash output as I get it onto the terminal, rather than writing all the command output at the end.
Not with bash itself, but via the tee command:
zipper -x -n in geany | tee log.txt
&>>FILE COMMAND
will append the output of COMMAND to FILE
In your case
&>>log.txt zypper -x -n in geany
If you want to pipe a command through a filter, you must assure that the command outputs to standard output (file descriptor 1) -- if it outputs to standard error (file descriptor 2), you have to redirect the 2 to 1 before the pipe. Take into account that only stdout passed through a pipe.
So you have to do so:
2>&1 COMMAND | FILTER
If you want to grep the output and in the same keep it into a log file, you have to duplicate it with tee, and use a filter like ... | tee log-file | grep options
If I execute
$ java -jar selenium-server.jar 2>&1 | grep "jetty.Server"
I get, after a while, the output I expect:
$ 16:30:24.881 INFO - Started org.openqa.jetty.jetty.Server#6b0a2d64
But I i try to redirect grep output to a file, it doesn't write a thing
$ java -jar selenium-server.jar 2>&1 | grep "jetty.Server" > /tmp/ebook_selenium
Any idea why? Thanks
We found that grep flushes its output when it writes to stdout but not to a file.
grep --line-buffered will force grep to output each line as it's processed.
I would like to replace all "no" by "on" in the console output of g++. I tried
$ g++ | sed -e 's/no/on/g'
But it shows
i686-apple-darwin9-g++-4.0.1: no input files
instead of
i686-apple-darwin9-g++-4.0.1: on input files
The message is arriving on the standard error, but the shell pipe operator connects the standard output of one process to the standard input of the next.
To reroute stderr, use
$ g++ 2>&1 | sed -e 's/no/on/g'
or
$ g++ |& sed -e 's/no/on/g'
to get
g++: on input files