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!

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

Postby DeadTOm76 » 2018-10-07 18:45

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!
User avatar
DeadTOm76
 
Posts: 10
Joined: 2017-09-22 15:36
Location: Missoula, MT USA

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

Postby cronoik » 2018-10-08 00:06

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!
cronoik
 
Posts: 275
Joined: 2015-05-20 21:17

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

Postby DeadTOm76 » 2018-10-08 02:55

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
DeadTOm76
 
Posts: 10
Joined: 2017-09-22 15:36
Location: Missoula, MT USA

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

Postby dilberts_left_nut » 2018-10-08 04:22

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...
User avatar
dilberts_left_nut
 
Posts: 4887
Joined: 2009-10-05 07:54
Location: enzed


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable