My script will be like this when I pass all servers in the array it will work. If I pass a single server as well it should go through loop and start/stop single one only. Can someone help me on this?
Input : ./script.sh shut_all_vm $2 $3 $VM Ex : ./script.sh shut_all_vm perf-loadgen2
If i pass the "perf-loadgen2" as param to script like above example it would start that VM only by entering into the loop.
If I didn't pass any args to script (just calling ./script.sh) it would go through each server in the array and start all VM's
shut_all_vm(){
cd $WORKSPACE/$SCRIPTS_DIR
declare -a VMs=("$@" $@-"perf-ld" $@-"perf-ld2" $@-"perf-loadgen2")
for i in "${VMs[@]}"
do
echo "$i"
az login $2 $3
az vm stop --resource-group $RESOURCE_GROUP --name $i
az vm deallocate -g $RESOURCE_GROUP -n $i
echo "$i server has been stopped successfully..."
done
}
$1 $2 $3 $VM