Skip to content

Instantly share code, notes, and snippets.

@neidiom
Forked from agarzon/googleize.sh
Last active February 19, 2018 17:08
Show Gist options
  • Save neidiom/a433eb3b3a1093329152e743b9b7fe2f to your computer and use it in GitHub Desktop.
Save neidiom/a433eb3b3a1093329152e743b9b7fe2f to your computer and use it in GitHub Desktop.
Change a domain's ip address from old one to new one via Plesk cli dns util
#!/bin/bash
if [ -z "$1" ]
then
echo "Please provide a domain name as argument"
exit 1
fi
if [ -z "$2" ]
then
echo "Please provide a new IP address"
exit 1
fi
DOMAIN=$1
NEW_IP=$2
echo "Provided domain name is ${DOMAIN}"
echo "Provided NEW IP ADDRESS is ${NEW_IP}"
IP=`dig +short A $DOMAIN`
# Delete records
/usr/local/psa/bin/dns -d ${DOMAIN} -a '' -ip ${IP}
/usr/local/psa/bin/dns -d ${DOMAIN} -a 'mail' -ip ${IP}
/usr/local/psa/bin/dns -d ${DOMAIN} -a 'webmail' -ip ${IP}
/usr/local/psa/bin/dns -d ${DOMAIN} -txt 'v=spf1 +a +mx -all'
# Create records
/usr/local/psa/bin/dns -d ${DOMAIN} -a '' -ip ${NEW_IP}
/usr/local/psa/bin/dns -d ${DOMAIN} -a 'mail' -ip ${NEW_IP}
/usr/local/psa/bin/dns -d ${DOMAIN} -a 'webmail' -ip ${NEW_IP}
/usr/local/psa/bin/dns -a ${DOMAIN} -txt "v=spf1 +a +mx ip4:${NEW_IP} -all"
#
/usr/local/psa/bin/dns --off ${DOMAIN}
/usr/local/psa/bin/dns --on ${DOMAIN}
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment