From d2f7f6c93e68d55036d4a75ced10aeb63615f20e Mon Sep 17 00:00:00 2001 From: Lenny Chen Date: Tue, 21 Nov 2023 11:15:30 -0800 Subject: [PATCH] chore: add logic for error handling --- edge/vmware/clone_vm_template/delete-packer-cache.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/edge/vmware/clone_vm_template/delete-packer-cache.sh b/edge/vmware/clone_vm_template/delete-packer-cache.sh index f150072..875b959 100644 --- a/edge/vmware/clone_vm_template/delete-packer-cache.sh +++ b/edge/vmware/clone_vm_template/delete-packer-cache.sh @@ -10,8 +10,10 @@ if [ $? -ne 0 ]; then fi # Now, try to list the packer_cache directory -govc datastore.ls -ds=$vcenter_datastore /packer_cache -if [ $? -ne 0 ]; then +PACKER_CACHE_OUTPUT=$(govc datastore.ls -ds=$vcenter_datastore /packer_cache 2>&1) +PACKER_CACHE_STATUS=$? + +if [ $PACKER_CACHE_STATUS -ne 0 ]; then echo "Existing packer cache not found. Nothing to delete." else # Cache exists, attempt to delete it