#!/bin/sh IPA="$(/usr/local/libexec/sockip | head -n1)" IPB="$(/usr/local/libexec/peerip | head -n1)" #read the ports from stdin to be looked up. #in the format: PORT, PORT\r\n read LINE PB="$(printf "%s" "$LINE" | cut -d, -f1 | tr -cd "[0-9]")" PA="$(printf "%s" "$LINE" | cut -d, -f2 | tr -cd "[0-9]")" #example output: #57132,6667:USERID:UNIX:segfault #5132,6667:ERROR:NO-USER USER="$(getent passwd "$(tcpident $IPA $PA $IPB $PB)" | cut -d: -f1)" if [ "_$USER" != "_" ];then printf "%s,%s:USERID:UNIX:%s\r\n" "$PB" "$PA" "$USER" else printf "%s,%s:ERROR:NO-USER\r\n" "$PB" "$PA" fi