forked from n0use/sh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnet
More file actions
30 lines (28 loc) · 862 Bytes
/
net
File metadata and controls
30 lines (28 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function newhost() {
host=$1
ipaddr=$2
if [ -z "$host" ] || [ -z "$ipaddr" ] ; then
echo "Usage: newhost hostname ipaddr"
return 1
fi
if [ -f /tmp/newhost.lck ] ; then
echo "There is currently a lock on newhost - "
echo "Check that everything is OK, remove /tmp/newhost.lck, and try again."
return 1
fi
touch /tmp/newhost.lck
type=""
if egrep "^[0-9\.]*[[:space:]]*${1}" /etc/hosts > /dev/null 2>&1 ; then
type="Updated"
sudo sed -i "s/^.*[[:space:]]${host}/${ipaddr} ${host}/" /etc/hosts
else
type="New"
cp /etc/hosts /tmp/hosts.$$
echo "$ipaddr $host" >> /tmp/hosts.$$
sudo mv -f /tmp/hosts.$$ /etc/hosts
fi
echo "${type} entry: "
grep -n "[[:space:]]${host}" /etc/hosts
rm /tmp/newhost.lck
return 0
}