Skip to content

Instantly share code, notes, and snippets.

@gowatana
Created January 29, 2020 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gowatana/2433eb1238ff56f22cca842ef5cc98e5 to your computer and use it in GitHub Desktop.
Save gowatana/2433eb1238ff56f22cca842ef5cc98e5 to your computer and use it in GitHub Desktop.
acli で VM 削除自動化くん。(Bash)
#!/bin/bash
KEEP_VM_LIST=$1
DELETE_FLAG=$2
if [ ! -f "$KEEP_VM_LIST" ]; then
echo "KEEP_VM_LIST $KEEP_VM_LIST not found."
exit 1
fi
acli vm.list | grep -E -v "^VM name|^$" | awk '{print $1}' | while read VM
do
grep $VM $KEEP_VM_LIST > /dev/null && echo "$VM => keep"
grep $VM $KEEP_VM_LIST > /dev/null || echo "$VM => delete"
if [ "$DELETE_FLAG" == "delete" ]; then
grep $VM $KEEP_VM_LIST > /dev/null || acli -y vm.delete $VM
fi
done
@gowatana
Copy link
Author

下記の投稿むけ。

acli で VM 削除自動化くん。(Bash スクリプト編)
https://blog.ntnx.jp/entry/2020/01/30/082317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment