#!/bin/bash
#

ID=$(docker ps | awk 'NR!=1{print $1}')

echo "$(date)" >> /tmp/openfile.txt
for id in $ID; do
    docker top $id | awk 'NR!=1{print $2,$(NF-1),$NF}' | while read pid comm arg; do
         openfiles=$(/sbin/lsof -p $pid 2>/dev/null | wc -l)
         echo "openfile: $openfiles, pid: $pid, $comm $arg:"
    done
done | sort -nr -k 2 >>  /tmp/openfile.txt
echo "##########################" >> /tmp/openfile.txt
