documentation/audit/dopackagelist

62 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2023-01-04 12:49:42 +01:00
#!/bin/bash
align_dpkgs()
{
local source_file="$1"
local letter="$2"
# Find the longest position.
local max=0
while read -r line; do
2023-01-07 16:56:44 +01:00
if [[ $line =~ '||/ N' ]]; then
local pos=$(expr index "$line" "$letter")
if (( $pos > $max)); then
max=$pos
fi
fi
2023-01-04 12:49:42 +01:00
done < "$source_file"
# Insert spaces.
local currentpos=0
local middle=""
while read -r line; do
2023-01-07 16:56:44 +01:00
#echo -e "$line\n"
if [[ $line =~ '||/ N' ]]; then
local currentpos=$(expr index "$line" "$letter")
currentpos=$(($currentpos-1))
local diff=$(($max-currentpos-1))
middle=$(printf %${diff}s)
local start=${line:0:currentpos}
local end=${line:currentpos}
echo "${start}${middle}${end}"
elif [[ $line =~ 'ii ' ]]; then
local start=${line:0:currentpos}
local end=${line:currentpos}
echo "${start}${middle}${end}"
fi
2023-01-04 12:49:42 +01:00
done < "$source_file"
}
# ##############################################################################
# Put all dpkg -l output in one file.
2023-01-07 16:56:44 +01:00
echo "" > tmp
2023-01-04 12:49:42 +01:00
for guest in $(cat machines.txt) ;
do
ssh -t admin666@$guest dpkg -l --no-pager >> tmp
done
# Align the column Version.
align_dpkgs "tmp" "V" > tmp2
# Align the column Architecture.
align_dpkgs "tmp2" "A" > tmp
# Output cleaned lines.
grep "^ii" tmp | sort | uniq
# Clean temprary files.
rm tmp tmp2