#!/bin/sh
#
# lsofdest - show destination network connections for each open public file
#
# usage:	lsofdest [ filesystem ] ...
# where:	filesystem is any valid mount point containing public files
#		default is /home and /home/ftp/mirror (adjust as needed)
#

for f in `lsof ${*-/home /home/ftp/mirror}|sed -n 's,.*[rwu][ NrRwWuUxX]  REG .* /,/,p'|sort -u`
do
    if [ -f "$f" ]
    then
	echo "$f"
	for p in `lsof -t "$f"`
	do
		#lsof -p $p | sed -n 's/.*->/	/p'
		lsof -p $p | fgrep -v ':ftp->' |
			#sed -n 's/.*:\(.*->.*:.*\) (ESTABLISHED)/	\1/p'
			sed -n 's/\([^ ]*\).*:\(.*->.*:.*\) (ESTABLISHED)/	\1:\2/p' |
			sed 's/	\([^:]*\)d*:\(\1s*\)->/	\2->/p' | uniq
	done
    fi
done
