Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Piping the output of a tail | grep command into a text file

Here you can discuss every aspect of Debian. Note: not for support requests!
Post Reply
Message
Author
User avatar
DeadTOm76
Posts: 54
Joined: 2017-09-22 15:36
Location: USA
XMMP/Jabber: deadtom@deadtom.me

Piping the output of a tail | grep command into a text file

#1 Post by DeadTOm76 »

My phone is occasionally having some trouble on my home network, and I'm trying to get a feel for what's happening as it goes in and out of my firewall.

I can run this command and watch the traffic in real time:

Code: Select all

tail -f /var/log/syslog | grep "<phone-ip>"
What I want to do is pipe that into a text file so that I can let it go for a few hours, and go over it later.

This is the command I'm running:

Code: Select all

tail -f /var/log/syslog | grep "<phone-ip>" > phone.log
I'm clearly doing something wrong though, because all this produces is a blank phone.log.

Any idea what I'm doing wrong here?

Thanks!

cronoik
Posts: 310
Joined: 2015-05-20 21:17

Re: Piping the output of a tail | grep command into a text f

#2 Post by cronoik »

You need buffering [1]:

Code: Select all

tail -f /var/log/syslog | grep --line-buffered "<phone-ip>" > phone.log
[1] http://mywiki.wooledge.org/BashFAQ/009
Have a nice day!

User avatar
DeadTOm76
Posts: 54
Joined: 2017-09-22 15:36
Location: USA
XMMP/Jabber: deadtom@deadtom.me

Re: Piping the output of a tail | grep command into a text f

#3 Post by DeadTOm76 »

cronoik wrote:You need buffering [1]:

Code: Select all

tail -f /var/log/syslog | grep --line-buffered "<phone-ip>" > phone.log
[1] http://mywiki.wooledge.org/BashFAQ/009

Yup, that did it. Thanks!

User avatar
dilberts_left_nut
Administrator
Administrator
Posts: 5346
Joined: 2009-10-05 07:54
Location: enzed
Has thanked: 13 times
Been thanked: 66 times

Re: Piping the output of a tail | grep command into a text f

#4 Post by dilberts_left_nut »

Or you could just ‘grep phoneip /var/log/syslog’ at the end of your test period.
AdrianTM wrote:There's no hacker in my grandma...

Post Reply