improve dps.sh output

This commit is contained in:
Marco Ochse 2017-08-07 10:24:25 +00:00
parent 36bb76d999
commit b25caf6302

View file

@ -1,41 +1,70 @@
#/bin/bash #/bin/bash
# Show current status of all running containers # Show current status of all running containers
# Let's ensure normal operation on exit or if interrupted ... myPARAM="$1"
function fuCLEANUP { myIMAGES="$(cat /etc/tpot/tpot.yml | grep -v '#' | grep container_name | cut -d: -f2)"
stty sane myRED=""
} myGREEN=""
trap fuCLEANUP EXIT myBLUE=""
myWHITE=""
myMAGENTA=""
function fuCONTAINERSTATUS {
local myNAME="$1"
local mySTATUS="$(/usr/bin/docker ps -f name=$i --format "table {{.Status}}" -f status=running -f status=exited | tail -n 1)"
myDOWN="$(echo "$mySTATUS" | grep -o -E "(STATUS|NAMES|Exited)")"
case "$myDOWN" in
STATUS)
mySTATUS="$myRED"DOWN"$myWHITE"
;;
NAMES)
mySTATUS="$myRED"DOWN"$myWHITE"
;;
Exited)
mySTATUS="$myRED$mySTATUS$myWHITE"
;;
*)
mySTATUS="$myGREEN$mySTATUS$myWHITE"
;;
esac
printf "$mySTATUS"
}
function fuCONTAINERPORTS {
local myNAME="$1"
local myPORTS="$(/usr/bin/docker ps -f name=$i --format "table {{.Ports}}" -f status=running -f status=exited | tail -n 1 | sed s/","/",\n\t\t\t\t\t\t\t"/g)"
if [ "$myDOWN" != "(STATUS|NAMES|Exited)" ];
then
printf "$myBLUE$myPORTS$myWHITE"
fi
}
function fuGETSYS {
printf "========| System |========\n"
printf "%+10s %-20s\n" "Date: " "$(date)"
printf "%+10s %-20s\n" "Uptime: " "$(uptime | cut -b 2-)"
printf "%+10s %-20s\n" "CPU temp: " "$(sensors | grep 'Physical' | awk '{ print $4" " }' | tr -d [:cntrl:])"
echo
}
stty -echo -icanon time 0 min 0
myIMAGES=$(cat /etc/tpot/tpot.yml | grep -v '#' | grep container_name | cut -d: -f2)
while true while true
do do
echo "" fuGETSYS
echo "======| System |======" printf "%-19s %-36s %s\n" "NAME" "STATUS" "PORTS"
echo Date:" "$(date)
echo Uptime:" "$(uptime)
echo CPU temp: $(sensors | grep "Physical" | awk '{ print $4 }')
echo
printf "NAME"
printf "%-15s STATUS"
printf "%-13s PORTS\n"
for i in $myIMAGES; do for i in $myIMAGES; do
mySTATUS=$(/usr/bin/docker ps -f name=$i --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}\t" -f status=running -f status=exited | GREP_COLORS='mt=01;35' /bin/egrep --color=always "(^[_0-9a-z-]+ |$)|$" | GREP_COLORS='mt=01;32' /bin/egrep --color=always "(Up[ 0-9a-Z ]+ |$)|$" | GREP_COLORS='mt=01;31' /bin/egrep --color=always "(Exited[ \(0-9\) ]+ [0-9a-Z ]+ ago|$)|$" | tail -n 1) myNAME="$myMAGENTA$i$myWHITE"
myDOWN=$(echo "$mySTATUS" | grep -c "NAMES") printf "%-32s %-49s %s" "$myNAME" "$(fuCONTAINERSTATUS $i)" "$(fuCONTAINERPORTS $i)"
if [ "$myDOWN" = "1" ]; echo
if [ "$myPARAM" = "vv" ];
then then
printf "%-19s Down\n" $i /usr/bin/docker exec -t "$i" /bin/ps awfuwfxwf | egrep -v -E "awfuwfxwf|/bin/ps"
else
printf "$mySTATUS\n"
fi
if [ "$1" = "vv" ];
then
/usr/bin/docker exec -t $i /bin/ps awfuwfxwf | egrep -v -E "awfuwfxwf|/bin/ps"
fi fi
done done
if [[ $1 =~ ^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$ ]]; if [[ $myPARAM =~ ^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$ ]];
then then
sleep $1 sleep "$myPARAM"
else else
break break
fi fi