linux - grep and tee to identify errors during installation -


in order identify if installation has errors should notice, using grep command on file , write file using tee because need elevate permissions.

sudo grep -inw ${logfolder}/$1.log -e "failed" | sudo tee -a ${logfolder}/$1.errors.log sudo grep -inw ${logfolder}/$1.log -e "error" | sudo tee -a ${logfolder}/$1.errors.log 

the thing file created if grep didn't find anything. there way can create file if grep found match ?

thanks

you may replace tee awk, won't create file if there nothing write it:

... | sudo awk "{print; print \$0 >> \"errors.log\";}" 

but such feature of awk used. i'd rather remove empty error file if nothing found:

test -s error.log || rm -f error.log 

and, way, may grep multiple words simultaneously:

grep -e 'failed|error' ... 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -