Uncategorized

op5-plugin | check_new_lvms

#!/bin/bash
excludedLVMS=$1
daystoinform=$2
AllLVMs=$(sudo lvdisplay | grep -B 4 -A 4 “LV Name” | grep “LV Name” | cut -d ‘ ‘ -f20)
exitval=0
currenttime=`date +%s -d “$daystoinform day ago”`
for i in $AllLVMs
do
lvcreation=$(sudo lvdisplay | grep -w $i -A4 | grep Creation | cut -d ‘,’ -f3 | cut -c 2-12)
lvcreationinEpoch=`date -d”$lvcreation” +%s`
epochtodate=$(date -d @$lvcreationinEpoch)
checkexcluded=$(echo $excludedLVMS | grep -wc “$i” )
if [[ “$lvcreationinEpoch” -gt “$currenttime” && $checkexcluded -lt 1 ]]; then
echo “new LVM createad: $i on $epochtodate”
exitval=1
fi
done
echo “Current LVMs: $AllLVMs”
exit $exitval