Can someone tell me if what I'm trying to do with this script will work? This is in addition to my other question here: How to pass Bash variables as Python arguments
hostnames=hosts.txt
#sets zone as a string into $zone variable
zone="domain.local"
#stores text file into $ip variable
ip=ip.txt
#creates an array
declare -a ipArray
#puts all the contents of the ip.txt file into the ipArray array
ipArray=(`cat "$ip"`)
#increment variable used to access each value in the ipArray array
i=0
#reads the contents of the hosts.text file
while read -r host; do
#for each host set the zone with the $zone variable
#for each host set the record-key to the name of each hostname being passed in via the $host variable defined in while loop
#for each host set the record-value to the current value of the ipArray array based on the index specified in the $i variable
sudo dns_cli.py --action=delete --zone=$zone --record-type=A --record-key=$host --record-value=${ipArray[i]} >> dns_delete.log 2>&1
#increment the $i variable by 1
i=$((i+1))
done < hosts.txt
I ran some echo tests and this appears to be printing out what I want, but I wanted additional input to see if it'll work. I basically need to supply a hostname and the associated IP address so this was the only way I could think of to loop through each host and substitute the IP with each iteration.
I also don't know if i should be enclosing the ${ipArray[i]} part in quotes. Excuse the ugly code, my experience with Bash is pretty much nonexistent.