Luc Lagarde
Luc Lagarde

Reputation: 95

Exclude some errors from python script in linux

I want to exclude some erros from log. I'm using a Raspberry 3b+.

I use

main.py >> log.txt 2>&1 | grep -v "Network is unreachable"

My error that I don't want is

[tcp @ 0x19ccea0] Connection to tcp://192.168.1.32:554?timeout=0 failed: Network is unreachable

I can put the whole error in grep because the ip adress may change

However this error is still in my log.txt file when I run my main.py

Upvotes: 0

Views: 17

Answers (1)

Barmar
Barmar

Reputation: 782130

You need to pipe to grep, and then redirect grep's output to the file. You're redirecting all the output to the file, so nothing goes to grep.

main.py 2>&1 | grep -v "Network is unreachable" >> log.txt

Upvotes: 1

Related Questions