Pages

Wednesday, May 4, 2016

Bash script to get hostname or ip address from /etc/hosts file, if not add to /etc/hosts file


#!/bin/bash
######Developed By - Krunal Patel(Linux Admin)#####
getent hosts $1 | grep $1
if [ $? == 0 ]; then
echo "hostname or ip address " {$1} " exists in /etc/hosts file"
else
read -p "please enter hostname to be added in /etc/hosts file : " hos
read -p "please enter ip address to be added in /etc/hosts file for $hos : " ipa
echo "$ipa $hos" >> /etc/hosts
fi
######Copyright © Krunal Patel (Shell Script Developer)######

No comments:

Post a Comment

Please give us suggestions.

Shell Script Code