My voip phone adapter generates a log entry when a call comes in. I managed to forward it to the syslog of my local ubuntu machine, to a file called /var/log/linksys.log.
Now I’d like to use it as instant caller ID display. The important line includes the string “INVITE sip”, so I tried:
tail /var/log/linksys.log -f | grep "INVITE sip"
but this brings the WHOLE line. I’m only interested in the part with the caller name and phone, between the strings “From:” and the first @ sign after it.
My goal would be to be able to follow the file with tail -f or similar (tried multitail too) but only have it show the name and phone nr when a new relevant line gets added to the log. (The log receives other lines too)
Here is a sample line:
Apr 8 01:06:10 INVITE sip: 999999@192.168.0.102:5060 SIP/2.0#015#012Via: SIP/2.0/UDP 111.111.11.111:5060;branch=z9hG4bK5f142476;rport#015#012From: "SMITHSON D" <sip:8885551234@111.111.11.111>;tag=as410515ed#015#012To: <sip:999999@192.168.0.102:5060>#015#012Contact: <sip:8885551234@111.111.11.111>#015#012Call-ID: 50354db42555555555aab68633cbb2e4@111.111.11.111#015#012CSeq: 102 INVITE#015#012User-Agent: VoIPMS/SERAST#015#012Max-Forwards: 70#015#012Remote-Party-ID: "SMITHSON D" <sip:8885551234@111.111.11.111>;privacy=off;screen=no#015#012Date: Sun, 08 Apr 2012 05:06:10 GMT#015#012Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO#015#012Supported: replaces#015#012Content-Type: application/sdp#015#012Content-Length: 291#015#012#015#012v=0#015#012o=root 18702 18702 IN IP4 111.111.11.111#015#012s=session#015#012c=IN IP4 111.111.11.111#015#012t=0 0#015#012m=audio 33100 RTP/AVP 0 18 101#015#012a=rtpmap:0 PCMU/8000#015#012a=rtpmap:18 G729/8000#015#012a=fmtp:18 annexb=no#015#012a=rtpmap:101 telephone-event/8000#015#012a=fmtp:101 0-16#015#012a=silenceSupp:off - - - -#015#012a=ptime:20#015#012a=sendrecv#015
Much thanks for any assistance…
Try using
awk.Here is my gawk one-liner(uses gawk third argument extension to match):
The same script with prettier printing:
Just pipe output of grep into this gawk script: