Files
ProxmoxHelper/DistroInventory.sh
Bram Prieshof ea8cf5b3d7 DistroInventory: fixed Variable type in loops
Varable in a loop can't be a local type

Fixed not cleaning up type variable
2023-11-19 23:02:32 +01:00

48 lines
1.3 KiB
Bash

#!/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
STATUS=$(pct status $ID |sed 's/status: //')
NAME=$(pct config $ID | grep hostname |sed 's/hostname: //')
if [ $STATUS == "running" ]; then OSRELEASE=$(pct exec $ID -- cat /etc/os-release);fi
ParseOSRelease
unset OSRELEASE TYPE ID NAME STATUS DISTRO VERSION
done
unset TYPE
fi
#VM Updates
if $CheckCT; then
TYPE=VM;
for ID in $(qm list | tail -n+2 | awk '{print $1}'); do
STATUS=$(qm status $ID |sed 's/status: //')
NAME=$(qm config $ID | grep name |sed 's/name: //')
if [ $STATUS == "running" ]; then OSRELEASE=$(qm guest exec 2002 -- cat /etc/os-release |jq -r '.["out-data"]')
ParseOSRelease
unset OSRELEASE TYPE ID NAME STATUS DISTRO VERSION
done
unset TYPE
fi