From f3f6f7006e9eaf2d74d7a7c72cb73a50114f0c3e Mon Sep 17 00:00:00 2001 From: hjp Date: Thu, 6 May 2004 12:26:36 +0000 Subject: [PATCH] findsock --- tiny/GNUmakefile | 1 + tiny/findsock | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100755 tiny/findsock diff --git a/tiny/GNUmakefile b/tiny/GNUmakefile index 8464a8d..e7e6ad9 100644 --- a/tiny/GNUmakefile +++ b/tiny/GNUmakefile @@ -17,6 +17,7 @@ install: \ $(BINDIR)/psg \ $(BINDIR)/save \ $(BINDIR)/savedate \ + $(BINDIR)/findsock \ fnp: fnp.sh fnpa: fnpa.sh diff --git a/tiny/findsock b/tiny/findsock new file mode 100755 index 0000000..fff5a17 --- /dev/null +++ b/tiny/findsock @@ -0,0 +1,19 @@ +#!/bin/sh +# +# Stupid little program to find the socket of stdin of the parent +# of the specified process. Normally this is used for the +# login shell to determine to which of several virtual hosts the +# user connected. + +if [ $# -eq 0 ] +then + echo "Usage: $0 " >&2 + exit 1 +fi + +pid=$1 + +ppid=`ps -ef | awk -v pid=$pid '$2 == pid { print $3 }'` + +sock=`lsof -p $ppid 2>/dev/null | awk '$4 == "0u" && $5 == "inet" { print $9 }'` +echo $sock