Added script for generating a CSV file of CT/VM Guests

This commit is contained in:
2023-11-19 22:59:38 +01:00
parent 2d760c856d
commit cf0e4928ca
3 changed files with 63 additions and 1 deletions

3
.gitignore vendored
View File

@@ -1 +1,2 @@
logs/*
logs/*
*.csv

45
DistroInventory.sh Normal file
View File

@@ -0,0 +1,45 @@
#!/bin/bash
##########################################
# ProxMox update tools #
# Get OS release info on all CT`s/VM`s #
# @author: Bram Prieshof #
##########################################
#Dirs
WorkDir=$(dirname $0)
#InventoryFile
InventoryFile=$WorkDir/GuestInventory.csv
#Load functions
source $WorkDir/functions.sh
#Create Log folder
#Get what sould be checked
CheckVM=true
CheckCT=true
echo "Type,ID,Name,Status,Distro,Version" | tee $InventoryFile
#CT updates
if $CheckVM; then
TYPE=CT;
for ID in $(pct list | tail -n+2 | awk '{print $1}'); do
local STATUS=$(pct status $ID |sed 's/status: //')
local NAME=$(pct config $ID | grep hostname |sed 's/hostname: //')
if [ $STATUS == "running" ]; then local OSRELEASE=$(pct exec $ID -- cat /etc/os-release);fi
ParseOSRelease
unset OSRELEASE TYPE ID NAME STATUS DISTRO VERSION
done
fi
#VM Updates
if $CheckCT; then
TYPE=VM;
for ID in $(qm list | tail -n+2 | awk '{print $1}'); do
local STATUS=$(qm status $ID |sed 's/status: //')
local NAME=$(qm config $ID | grep name |sed 's/name: //')
if [ $STATUS == "running" ]; then local OSRELEASE=$(qm guest exec 2002 -- cat /etc/os-release |jq -r '.["out-data"]')
ParseOSRelease
unset OSRELEASE TYPE ID NAME STATUS DISTRO VERSION
done
fi

View File

@@ -208,4 +208,20 @@ UpgradeRelease () {
echo "Warning: Release upgrade are supported for this distro"
#exit 100
fi
}
ParseOSRelease()
{
if [ ! -z "$OSRELEASE" ]; then
DISTRO=$(printf "$OSRELEASE" | awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
VERSION=$(printf "$OSRELEASE" | awk -F= '$1=="VERSION_ID" { print $2 ;}' /etc/os-release |tr -d '"' )
VERSIONNAME=$(printf "$OSRELEASE" | -- awk -F= '$1=="VERSION_CODENAME" { print $2 ;}' /etc/os-release)
if [ ! -z "$VERSIONNAME" ]; then
VERSION="$VERSION ($VERSIONNAME)"
fi
else
DISTRO=N/A
VERSION=N/A
fi
echo "$TYPE,$ID,$NAME,$STATUS,$DISTRO,$VERSION" | tee -a $InventoryFile
}