Created
January 29, 2020 23:12
-
-
Save gowatana/2433eb1238ff56f22cca842ef5cc98e5 to your computer and use it in GitHub Desktop.
acli で VM 削除自動化くん。(Bash)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
下記の投稿むけ。
acli で VM 削除自動化くん。(Bash スクリプト編)
https://blog.ntnx.jp/entry/2020/01/30/082317