Added add_domain_slave.sh

Script to add a DNS slave zone automatically (on Evolix servers).
This commit is contained in:
Benoît S. 2019-03-22 09:47:26 +01:00
parent 0ae9645f88
commit dc04977a61
1 changed files with 43 additions and 0 deletions

43
scripts/add_domain_slave.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/bash
slaveServer="ns.slave.example.com"
sshUser="example"
clientName="example"
webServerName="example"
mailAddress="admin@example.com"
usage() {
cat <<EOT
$0 domain_to_add
Exemple: $0 mydomain.com
EOT
exit 1
}
if [[ $# != 1 ]]; then
echo "Need only one argument!"
usage
fi
domain=$1
# Remove www. if any.
domain=${domain#www.}
# Connect to $slaveServer and add slave domain.
stdin=/tmp/empty-in
stdout=/tmp/empty-out
result=/tmp/result
[[ -e $stdin ]] && rm -f $stdin
[[ -e $stdout ]] && rm -f $stdout
empty -f -i $stdin -o $stdout -L $result ssh ${sshUser}@${slaveServer} "sudo /usr/share/scripts/bind-slave-${clientName}.sh"
# Responses to question of add slave domain script.
sleep 2
echo "$domain" > $stdin
sleep 2
# Send mail
subject="[AUTO-${clientName}] Added slave domain of $webServerName $domain"
mail -s "$subject" $mailAddress < $result
cat $result
# Cleaning
rm $result