Skip to content

Instantly share code, notes, and snippets.

@alleck
Last active August 29, 2015 14:18
Show Gist options
  • Save alleck/3819a70b3cf83efa5e03 to your computer and use it in GitHub Desktop.
Save alleck/3819a70b3cf83efa5e03 to your computer and use it in GitHub Desktop.
Change cPanel Server Hostname
#!/bin/bash
#Author: Kaleb Lewis (Alleck)
#Purpose: Change Hostname
#OS: CentOS/REHL
#Language: BASH
clear
echo "Please Enter New Hostname"
read HOSTNAME
#/etc/sysconfig/network
if [ -f "/etc/sysconfig/network" ]
then
sed -i.BAK -e "s/HOSTNAME=.*/HOSTNAME=$HOSTNAME/" /etc/sysconfig/network
fi
#/etc/sysconfig/networking/profiles/default/network
if [ -f "/etc/sysconfig/networking/profiles/default/network" ]
then
sed -i.BAK -e "s/HOSTNAME=.*/HOSTNAME=$HOSTNAME/" /etc/sysconfig/networking/profiles/default/network
fi
#/etc/localdomains
if [ -f "/etc/localdomains" ]
then
sed -i.BAK "s/.*/$HOSTNAME/g" /etc/localdomains
fi
#/etc/wwwacct.conf
if [ -f "/etc/wwwacct.conf" ]
then
sed -i.BAK -e "s/HOST.*/HOST $HOSTNAME/g" /etc/wwwacct.conf
fi
#/etc/hosts
#delete last line
ip=$(awk '/./{line=$0} END{print line}' /etc/hosts | awk '{ print $2 }')
pre=$(echo $HOSTNAME | cut -f1 -d".")
sed -i '$d' /etc/hosts
#add line
echo -e "$ip\t$HOSTNAME\t$pre" >> /etc/hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment