Each line of /etc/trueuserdomains contains a username and its associated domain. I am trying to do ln -s /home/$user /var/www/vhosts/$domain for each line. I'm able to define two arrays with the required information. However, I am having trouble iterating through the array in the proper order.
#!/bin/bash
domain=(`cat /etc/trueuserdomains | cut -d: -f1`)
user=(`awk '{print $2}' /etc/trueuserdomains`)
for x in "${domain[@]}"
do
for y in "${user[@]}"; do
ln -s /home/$y /var/www/vhosts/$x
done
done
This repeats a single domain for each username, i.e.:
domain1.com user1
domain1.com user2
domain1.com user3
Close, but I need:
domain1.com user1
domain2.com user2
domain3.com user3
So basically loop through the domain array using the user array in the proper order. Any ideas? It sounds like associative arrays may help but unfortunately this server has only Bash 3, which does not support them. Thanks in advance!
cat /etc/trueuserdomains | cut -d: -f1) user=(awk '{print $2}' /etc/trueuserdomains) for x in "${!domain[@]}" do ln -s /home/"${user[$x]}" /var/www/vhosts/"${domain[$x]}" done