Multi ip: Add a shared ipv6 to all users at once

As we are currently adding ipv6 to or live systems and servers contain at least 1000 domains a server it was not really handy to add every thing by hand and da it self does not really has a function cq script for it.

After searching the forum i fond 1 post that came in handy but not yet fully what i needed so i used this script as basic and changed it to my needs.

So credits for the base script go to Icehosting forum post http://www.directadmin.com/forum/sho…+ip+to+account

Ok i created the script and added it to:

Quote:

cd /usr/local/directadmin/script/custom/


and called it "add_ipv6_to_user.sh"

after creating the script chmod the file to 755

Quote:

chmod 755 add_ipv6_to_user.sh


The script: (off course change YOUR IPV6 ADDRESS THAT YOU WANT TO ADD to the ip address you want to add!)

Code:

#!/bin/sh

#Set the IP here
IP="YOUR IPV6 ADDRESS THAT YOU WANT TO ADD"
COUNTER="0"

#Does the IP address exist?
COUNT_IP="`grep -c ${IP} /usr/local/directadmin/data/admin/ip.list`"

if [ ${COUNT_IP} -eq 0 ]; then
  exit 1;
fi

for user in `ls /usr/local/directadmin/data/users`; do
{
  COUNT_IP_USER="`grep -c ${IP} /usr/local/directadmin/data/users/$user/user_ip.list`"
   
  if [ ${COUNT_IP_USER} -eq 0 ]; then
                          COUNTER="1"
 
                  echo "${IP}" >> /usr/local/directadmin/data/users/$user/user_ip.list
  fi
        for domain in `cat /usr/local/directadmin/data/users/$user/domains.list`; do
          {
                if [ -e /usr/local/directadmin/data/users/$user/domains/$domain.ip_list ]; then
               
                        if [ ${COUNTER} -eq 0 ]; then
                                COUNTER="1"
                        fi
                        COUNT_IP_DOMAIN="`grep -c ${IP} /usr/local/directadmin/data/users/$user/domains/$domain.ip_list`"
                        if [ ${COUNT_IP_USER} -eq 0 ]; then
               
                        echo "${IP}" >> /usr/local/directadmin/data/users/$user/domains/$domain.ip_list
                fi
                fi
               
                COUNT_IP_DNS="`grep -c ${IP} /var/named/$domain.db`"
                if [ ${COUNT_IP_DNS} -eq 0 ]; then
                       
                        if [ ${COUNTER} -eq 0 ]; then
                                COUNTER="1"
                        fi
               
                echo "ftp IN AAAA ${IP}" >> /var/named/$domain.db
                echo "mail IN AAAA ${IP}" >> /var/named/$domain.db
                echo "www IN AAAA ${IP}" >> /var/named/$domain.db
                echo "pop IN AAAA ${IP}" >> /var/named/$domain.db
                echo "smtp IN AAAA ${IP}" >> /var/named/$domain.db
                echo "$domain. IN AAAA ${IP}" >> /var/named/$domain.db
                fi
          }
          done;
}
done;

if [ ${COUNTER} -eq 1 ]; then
 echo "action=rewrite&value=named" >> /usr/local/directadmin/data/task.queue
 echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
fi
exit 0;


After the script is created you can run it with a cronjob for example:

Quote:

15 * * * * /usr/local/directadmin/script/custom/add_ipv6_to_user.sh >/dev/null 2>&1


Im not that great in bash scripts so iff you feel that i made any mistake or know a better way or if i forgot something feel free to correct me.