#
set noglob
#####Message Texts######
set mesg1 = "Enter nodes, in the form: Internet address<TAB>hostname<SP>aliases"
set mesg1b = "To end program, enter blank line at prompt."
set mesg2 = "Address "
set mesg2b = " has already been used, "
set mesg2c = "please reenter that node:"
set mesg3 = "Address must be in the form [1-255].[0-255].[0-255].[1-255]"
########################
touch hold
				# break off addresses for comparison
awk '{print $1}' /etc/hosts > addresses
				# initial prompt for input
echo $mesg1
echo $mesg1b

get_node:
				# signal that we're ready for more	
echo  -n "ready>"
set NODE = ($<)
				# exit on blank input
if ( $#NODE == 0) then
	goto add_host
endif
				# break address off input for uniqueness check
set ADRS = `echo $NODE | awk '{print $1}'` 
		  		# check uniqueness 
fgrep -s $ADRS addresses 
				# if its been used already ask to reenter
if ( $status != 1 ) then 
	echo $mesg2$ADRS$mesg2b$mesg2c
	goto get_node
endif
				# check that address is in range
echo $ADRS | grep -s '^[0-9]' 
if ( $status == 1 ) then
	goto bad_in
endif
echo $ADRS | awk '{FS="."} {print $1}' > test
if ( `cat test` < 1 | `cat test` > 255) then
	goto bad_in
endif
echo $ADRS | awk '{FS="."} {print $2}' > test
if ( `cat test` < 0 | `cat test` > 255) then
	goto bad_in
endif
echo $ADRS | awk '{FS="."} {print $3}' > test
if ( `cat test` < 0 | `cat test` > 255) then
	goto bad_in
endif
echo $ADRS | awk '{FS="."} {print $4}' > test
if ( `cat test` < 1 | `cat test` > 255) then
	goto bad_in
endif
				# otherwise add it to used list
echo $ADRS >> addresses
				# and to holding file, then get next
echo $NODE >> hold
goto get_node
				# add new entries to /etc/hosts
add_host:
sort hold > temp
				# rememove scratch files
/bin/rm -f temp
/bin/rm -f addresses
/bin/rm -f test
/bin/rm -f hold

exit(0)

bad_in:
echo $mesg3
echo $mesg2c
goto get_node
