Page 1 of 1

Mass change of NS records

Posted: Wed Feb 24, 2016 9:48 pm
by Felix
Vesta CP0.9.8R15 on Ubuntu 14.04

I have created USER1 and set DNS1 and DNS2 as the user's DNS servers. Every domain created by USER1 has DNS1 and DNS2 as NS records. At some point there was a need to change DNS2 to DNS3, so I went to edit the user in VESTA and replaced DNS2 with DNS3. But that didn't change the NS records in every domain owned by USER1.

Is there a way to massively change the NS records of every domain owned by USER1?

Re: Mass change of NS records

Posted: Thu Feb 25, 2016 8:09 am
by tjebbeke
You can use te API (check /usr/local/vesta/bin) to build a script. But it isn't possible in the UI.

Re: Mass change of NS records

Posted: Sat Feb 27, 2016 10:40 am
by Felix
A script is indeed a great idea but I'm no bash guru :-(
If anyone reading this could drop some help would be nice...

This could be the logic of the script but I can't code it:
v-script [user]

[user] argument should be used to check for files in directory /home/[user]/conf/dns/
for every file that is there, there should be a search and replace; search for DNS2 and replace with DNS3 in the line that contains "NS"
save each file

Re: Mass change of NS records

Posted: Mon Feb 29, 2016 9:55 pm
by skamasle
You can go to

Code: Select all

/usr/local/vesta/data/users/USER/dns
And use some comand like:

Code: Select all

replace -v "DNS2 "DNS3" -- *
man replace

Then rebuild DNS from vestacp to that user.

If you edit it on /home/[user]/conf/dns/ vesta will overwrite that files.

Re: Mass change of NS records

Posted: Wed Aug 31, 2016 4:00 am
by sacredwebsite
For anyone looking to do this easily (for a single user):

Code: Select all

#!/bin/bash
if [ $(whoami) != 'root' ]; then
  echo "Must be root to run $0"
  exit 1;
fi
echo "Enter Old IP" && read ip_old
echo "Enter New IP" && read ip_new
echo "Enter User Name" && read user
sed -i "s/${ip_old}/${ip_new}/g" /usr/local/vesta/data/users/${user}/dns/*
v-rebuild-dns-domains ${user}
exit 0
Or if you want to run this on all users:

Code: Select all

#!/bin/bash
if [ $(whoami) != 'root' ]; then
  echo "Must be root to run $0"
  exit 1;
fi
echo "Enter Old IP" && read ip_old
echo "Enter New IP" && read ip_new
declare -a user=$(v-list-sys-users plain)
for user in ${user[@]}; do
  sed -i "s/${ip_old}/${ip_new}/g" /usr/local/vesta/data/users/${user}/dns/*
  v-rebuild-dns-domains ${user}
done
exit 0

Re: Mass change of NS records

Posted: Tue Nov 29, 2016 10:42 pm
by Rhandy
Hello

Your script give on excelent idea for update dynamic dns. can you help me and change the script to:

I dont know write shell script

But i can get ip using this :

Code: Select all

#!/bin/bash
if [ $(whoami) != 'root' ]; then
  echo "Must be root to run $0"
  exit 1;
fi
ip_old= ### one file saved before with old_ip
ip_new= ### something like this ## curl http://ipecho.net/plain; echo
declare -a user=$(v-list-sys-users plain)
for user in ${user[@]}; do
  sed -i "s/${ip_old}/${ip_new}/g" /usr/local/vesta/data/users/${user}/dns/*
  v-rebuild-dns-domains ${user}
  
  ### save this new ip to file old_ip for next use###
  
done
exit 0



Re: Mass change of NS records

Posted: Wed Nov 30, 2016 12:41 pm
by Rhandy
Ok I´m done

:-)

Code: Select all

#!/bin/bash
if [ $(whoami) != 'root' ]; then
  echo "Must be root to run $0"
  exit 1;
fi
ip_old=`cat oldip`
ip_new=`curl http://ipecho.net/plain`
declare -a user=$(v-list-sys-users plain)
for user in ${user[@]}; do
  sed -i "s/${ip_old}/${ip_new}/g" /usr/local/vesta/data/users/${user}/dns/*
  v-rebuild-dns-domains ${user}
done
echo $ip_new >oldip
exit 0