From a22b7dda098bef0dcbb7e391831d25bd88cb6ed1 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 13 Jul 2022 14:53:52 +0000 Subject: [PATCH] first commit --- README.md | 0 listimages | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 README.md create mode 100755 listimages diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/listimages b/listimages new file mode 100755 index 0000000..1b38982 --- /dev/null +++ b/listimages @@ -0,0 +1,50 @@ +#!/bin/bash +#get all used images and their backing files +#list all unused qemu images in eve-ng +#will not include "wiped" nodes +#there cannot be any running nodes +# +#very "hacky" +# +#find /opt/unetlab/tmp -type f -name \*.qcow2 -exec qemu-img info {} \; > test +#set record delimiter to blank line +#sed -i s/\ \ \ \ corrupt:\ false// test +#sed -i s/\ \ \ \ corrupt:\ true// test +#parse w/ blank line for record separateor and newline for field separator +# 1 is image file (provisioned device) +# 2 is for the source +#awk 'BEGIN {FS="\n"; RS=""} {print $1 $6}' test > test2 +#awk 'BEGIN {FS="\n"; RS=""} {print $6}' test > test2 +#clean up leaving two files +#sed -i 's/image: //' test2 +#sed -i 's/backing file://' test2 +# list of all used images +#cat test2 | sort -k 2 -u +#cat test2 | sort -u +# +#get just the directory names for qemu (lists only used versions) +#cat test2 | cut -f 6 -d '/' +# +#cat test2 | sort -u | cut -f 6 -d '/' > test3 +# +#list installed qemu versions +#ls -l /opt/unetlab/addons/qemu/ | cut -b 42- > test4 +#grep -Fxv `ls -l /opt/unetlab/addons/qemu/ | cut -b 42-` test3 +#grep -Fxv -f test3 test4 +echo "Please enter username" +read USERNAME +echo "Please enter password" +read -s PASSWORD +rm list.json +curl -k -s -b /tmp/cookie -c /tmp/cookie -X POST -d '{"username":"'"$USERNAME"'","password":"'"$PASSWORD"'"}' https://127.0.0.1/api/auth/login +ls -R /opt/unetlab/labs/*.unl > labs_list +sed -i 's/\ /%20/g' labs_list +sed -i 's/\/opt\/unetlab//g' labs_list +while read i; do + curl -k -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' https://127.0.0.1/api$i/nodes >> list.json + #echo "$i"; + +done < labs_list +cat list.json | jq -r '.data' | grep image | sort -u + +