diff --git a/os_server.sh b/os_server.sh new file mode 100644 index 0000000..23e8c42 --- /dev/null +++ b/os_server.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# Script zur Ausgabe der Betriebssystemen von Linux-Servern +# Vorrausgesetzt sind: +# 1. eine Liste der Server in der Datei hosts.txt +# 2. befüllte ~/.ssh/config + +get_os_info() { + local host=$1 + + result=$(ssh -o ConnectTimeout=5 -o BatchMode=yes "$host" ' + if [ -f /etc/os-release ]; then + . /etc/os-release + echo "$NAME|$VERSION_ID|$(uname -r)" + elif [ -f /etc/redhat-release ]; then + echo "$(cat /etc/redhat-release)|unknown|$(uname -r)" + elif [ -f /etc/debian_version ]; then + echo "Debian|$(cat /etc/debian_version)|$(uname -r)" + else + echo "$(uname -s)|unknown|$(uname -r)" + fi + ' 2>/dev/null) + + if [ $? -eq 0 ]; then + echo "$host|$result" + else + echo "$host|CONNECTION_FAILED|-|-" + fi +} + +if [ ! -f "hosts.txt" ]; then + echo "ERROR: hosts.txt nicht gefunden!" >&2 + exit 1 +fi + +echo "Server|OS|Version|Kernel" + +echo "# Lese hosts.txt..." >&2 + +while read -r line; do + [[ -z "$line" ]] && continue + [[ "$line" =~ ^# ]] && continue + [[ "$line" =~ ^[[:space:]]*$ ]] && continue + + get_os_info "$line" +done < hosts.txt \ No newline at end of file