瀏覽代碼

Added lxd status script.

Yannick Boetzel 7 年之前
父節點
當前提交
5c472293f4
共有 1 個文件被更改,包括 29 次插入0 次删除
  1. 29 0
      60-lxd

+ 29 - 0
60-lxd

@@ -0,0 +1,29 @@
+#!/bin/bash
+
+# set column width
+COLUMNS=2
+# colors
+green="\e[1;32m"
+red="\e[1;31m"
+undim="\e[0m"
+
+mapfile -t containers < <(lxc list -c ns | awk '{ print $2,$4 }' | sed '/^\s*$/d' | tail -n +2)
+
+out=""
+for i in "${!containers[@]}"; do
+    IFS=" " read name status <<< ${containers[i]}
+    # color green if service is active, else red
+    if [[ "${status}" == "RUNNING" ]]; then
+        out+="${name}:,${green}${status,,}${undim},"
+    else
+        out+="${name}:,${red}${status,,}${undim},"
+    fi
+    # insert \n every $COLUMNS column
+    if [ $((($i+1) % $COLUMNS)) -eq 0 ]; then
+        out+="\n"
+    fi
+done
+out+="\n"
+
+printf "\nlxd status:\n"
+printf "$out" | column -ts $',' | sed -e 's/^/  /'