os_server.sh hinzugefügt
This commit is contained in:
parent
427049ef8a
commit
fadaa5f77c
1 changed files with 45 additions and 0 deletions
45
os_server.sh
Normal file
45
os_server.sh
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue