---------- Post updated at 05:55 AM ---------- Previous update was at 04:50 AM ----------
Hi,
Please, i have another question in the same context: how can i get the hostname of the machine i work on ?
Here is my script that i try to complete:
hostname=$(host $ipaddr | awk '{print substr($NF,1,length($NF)-1)}')
echo $hostname
$h= get the current hostname
if [ $hostname -ne $h ]
then
//instructions
fi
We should be little careful with command hostname as if by mistakenly(eg-> hostname NEW_NAME) we have given something like typo etc with it then it will set the hostname of the system to NEW_NAME(Which we had given as typo/unintentionally). This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations). Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh . But off course we should be root for same.