#!/bin/bash if [ ! $UID -eq 0 ]; then sudo $0 $1 exit fi echo $1 > /etc/hostname cat /etc/hosts | sed "s#^\\(127.0.0.1\\)\\(.*\\)\$#\\1 $1 \\2#g" > /etc/hosts.tmp mv /etc/hosts.tmp /etc/hosts hostname $1 if [ -f /etc/sysconfig/network ]; then echo -e "NETWORKING=yes\nHOSTNAME=$1\n" > /etc/sysconfig/network fi echo "Server renamed to $1"