simple/tiny/findsock

20 lines
455 B
Bash
Executable File

#!/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 <pid of login shell>" >&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