Script to Change IP of a cpanel domain
ALGORITHM
1) Get the word count(TLN) of /root/bobcares/iplist_username.txt file
2) Get the current ip of domain(CIP) from /root/bobcares/current_ip_username.txt
3) Find the line number(CLN) of CIP in /root/bobcares/iplist_username.txt
4) If CLN -eq WC_ ;then
set CLN=1
save CLN
take the first ip in IPlIST
assign ip to domain
sent alert to email address
2) Get the current ip of domain(CIP) from /root/bobcares/current_ip_username.txt
3) Find the line number(CLN) of CIP in /root/bobcares/iplist_username.txt
4) If CLN -eq WC_ ;then
set CLN=1
save CLN
take the first ip in IPlIST
assign ip to domain
sent alert to email address
else
CLN=CLN+1
Take the ip on line $CLN from IPlIST
save CLN
assign ip to domain
sent alert to email address
fi
5) End
#!/bin/bash # Created by Bobcares # USERNAME : cpanel username # IPLIST: List of IPs that will be assigned to the domain(each IP's will be listed in # CUR_IP: Contains the current IP assigned to the domain # CHANGEIP=/usr/local/cpanel/bin/setsiteip USERNAME=username IPLIST=/root/bobcares/iplist_username.txt CUR_IP=/root/bobcares/current_ip_username.txt ##REMOVE EMPTY LINES FROM FILE sed -i "/^$/d" iplist_username.txt #Current IP CIP=$(cat ${CUR_IP}) #Total line count TLN=$(wc -l ${IPLIST}|cut -d" " -f1) #Current line number CLN=$(grep -n ${CIP} ${IPLIST}|cut -d: -f1) echo -e "$CLN\n$TLN\n$CIP" if [ $CLN -eq $TLN ]; then CLN=1 echo ${CLN} > ${CUR_IP} sed -n 1p ${IPLIST} > ${CUR_IP} CIP=$(cat ${CUR_IP}) $CHANGEIP -u ${USERNAME} ${CIP} > ~/report_username.txt ret=$? echo -e "CLN=1\nRET=${ret}" else CLN=$((CLN+1)) echo ${CLN} > ${CUR_IP} sed -n "${CLN}"p ${IPLIST} > ${CUR_IP} CIP=$(cat ${CUR_IP}) $CHANGEIP -u ${USERNAME} ${CIP} > ~/report_username.txt ret=$? echo -e "CLN=${CLN}\nRET=${ret}" fi ####SEND ALERT#### ALERTEMAIL_=user8@hotmail.com if [ $ret -eq 0 ];then exit 0 #msg="IP CHANGED SUCCESSFULLY NEW IP=${CIP}" #echo "NOTIFICATION FROM `hostname`"| mail -s "${msg}" ${ALERTEMAIL_} else msg="IP CHANGED FAILURE IP TRIED=${CIP}" content=$(cat ~/report.txt) echo "$content" |mail -s "${msg}" ${ALERTEMAIL_} fi ####### ##END #######
Categories: Cpanel/WHM, Scripts
Definitely imagine that that you stated. Your favourite
reason appeared to be on the net the simplest thing to keep in mind of.
I say to you, I definitely get irked while folks think about
issues that they just do not recognise about. You managed
to hit the nail upon the highest and defined out the whole
thing without having side effect , folks can take a signal.
Will likely be again to get more. Thanks
Having read this I believed it was really informative.
I appreciate you spending some time and effort to put this
informative article together. I once again find myself personally spending
a lot of time both reading and leaving comments.
But so what, it was still worth it!
It’s really a nice and useful piece of information.
I am glad that you just shared this helpful info
with us. Please keep us informed like this. Thank you for sharing.
Nice post. I used to be checking constantly this weblog and I’m impressed!
Extremely helpful info particularly the closing
phase 🙂 I care for such info a lot. I used to
be looking for this particular information for a long time.
Thanks and good luck.