Hello Guys,
Can you kindly assist me and advise why my script is not working??
Code:
#!/bin/bash
set -x
# declare an array variable
declare -a host_list=("APREPAOS-1" "BPREPAOS-2" "APREPWEB-1" "AAPREPWEB-2" "PREPSQL-1" "PREPSQL-2" "PREPRDS-1" "PREPBI01" "SUPPORT-1")
## now loop through the above array
for i in "${host_list[@]}"
do
case ${i} in
[*AOS*])
export resource_group="rg_app"
;;
[*SQL*])
export resource_group="rg_sql"
;;
[*WEB*])
export resource_group="rg_app"
;;
[*RDS*])
export resource_group="rg_remote"
;;
[*BI*])
export resource_group="rg_sql"
;;
[*SUPPORT*])
export resource_group="rg_support"
;;
*)
Message="Invalid hostname , please check"
;;
esac
echo "Installing Windows Remote Management $i with resource group $resource_group "
# az vm run-command invoke --command-id RunPowerShellScript --resource-group "${resource_group}" --name "${i}" --scripts '(New-Object -TypeName System.Net.WebClient).DownloadFile("https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1", "$env:temp\ConfigureRemotingForAnsible.ps1")'
# az vm run-command invoke --command-id RunPowerShellScript --resource-group "${resource_group}" --name "${i}" --scripts 'powershell.exe -ExecutionPolicy ByPass -File "$env:temp\ConfigureRemotingForAnsible.ps1"'
# az vm run-command invoke --command-id RunPowerShellScript --resource-group "${resource_group}" --name "${i}" --scripts 'netsh advfirewall firewall add rule name="Allow WinRM (Http)" dir=in localport=5985 protocol=tcp action=allow enable=yes'
# az vm run-command invoke --command-id RunPowerShellScript --resource-group "${resource_group}" --name "${i}" --scripts 'netsh advfirewall firewall add rule name="Allow WinRM (Https)" dir=in localport=5986 protocol=tcp action=allow enable=yes'
done
exit 0
When I execute it always goes to the last one and says Invalid hostname, please check.
What I want to do is declare a host array and each host comes in a different resource group, hence the case statement.
Once the export is done, it will come and execute azure cli for that host.
No idea why it is not working, I followed the syntax from here:
http://tldp.org/LDP/Bash-Beginners-G...ect_07_03.html
Many thanks