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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -