-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdateHostFile.nsh
More file actions
57 lines (53 loc) · 1.22 KB
/
UpdateHostFile.nsh
File metadata and controls
57 lines (53 loc) · 1.22 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /usr/bin/nsh
#
################################################################
# Fred Breton, BMC Software - February 2014
################################################################
#
# Description: Add an entry in hosts file what ever is the OS or
# DNS.
#
################################################################
#
# Parameters:
# $1: Type of resolution
# $2: ipadresse
# $3: hostname
#
################################################################
#
# Revision: 1
#
################################################################
if [ $# -ne 3 ]
then
echo "
Usage:
UpdateHostFile.nsh resolution_type IP hostname
Where:
resolution_type - Type of IP resolution, value can be File or DNS
IP - IP address
hostname - Name that have to be resolve with the IP
"
exit 1
fi
RESTYPE=$1
IP=$2
HOSTNAME=$3
TMPFILE="hosttmp$(date +%d%H%M%S)"
OS=$(uname -s)
if [ $OS = "WindowsNT" ]
then
hostfile="/${${${$(nexec -e cmd /c echo %SystemRoot%)/:\\/\\}/\\//}%?}/System32/drivers/etc/hosts"
else
hostfile="/etc/hosts"
fi
if [ $RESTYPE=="File" ]
then
grep -v $IP $hostfile >$TMPFILE
echo "$IP\t$HOSTNAME" >>$TMPFILE
mv -f $TMPFILE $hostfile
else
echo "No code for DNS registration"
exit 1
fi