Bash-OS-Server/os_server.sh
2026-02-11 10:44:07 +01:00

45 lines
No EOL
1.2 KiB
Bash

#!/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