📄 makerevhosts
字号:
#!/bin/csh -f## mkrevhost - get hostnames out of /etc/hosts file, and produce# RR format entries suitable for insertion in /etc/named.hosts file## # Revision 1.2 89/03/07 18:33:38 evi# *** empty log message ***# # Revision 1.1 89/01/18 14:37:04 scott# Initial revision# # Revision 1.2 88/10/07 14:04:36 evi# spelling errors.# # Revision 1.1 88/10/07 13:19:46 evi# Initial revision# # Revision 1.8 88/07/25 17:16:09 forys# Changed PRIMARY server from sigi to boulder.# # Revision 1.7 88/05/06 15:11:57 forys# Forgot to remove "exit 0" used for previous tests.# # Revision 1.6 88/05/06 15:03:29 forys# Now uses tabs, rather than strings of spaces# Strip host-gateway and host-gw entries from hosts.rev file# # Revision 1.5 88/05/04 12:44:10 forys# Put header catenation after addhinfo script (for MX records).# # Revision 1.4 87/09/13 03:29:25 forys# Strips "-gateway" out of named.rev file.# # Revision 1.3 87/09/02 02:55:14 forys# Used "egrep ..." instead of "grep -w" to save sigi-gateway.# # Revision 1.2 87/09/02 02:34:53 forys# Make sure we done have duplicate entries for primaries.# Capability to automatically add RRs on host-specific basis.# # Revision 1.1 87/09/02 02:32:24 coggs# Initial revision# set HOSTSRC = "/usr/local/adm/hosts/hostsrc/hosts"set NETADMIN = "netadmin@boulder"set TERR = /tmp/mkrevhosts.terrset ERR = /tmp/mkrevhosts.errset AWKFILE = /tmp/mkrevhosts.awkset REVFILE = /tmp/mkrevhosts.revset HOSTFILE = /tmp/mkrevhosts.hosts set PRIMEHOSTS = "boulder"set NSDIR = /usr/local/adm/hosts/ns/cd $NSDIR# zero errfilecat /dev/null > $ERR ### convert 'Colorado.EDU' into 'colorado.edu'set OUTDOMAIN = Colorado.EDUset INDOMAIN = `echo $OUTDOMAIN | tr A-Z a-z`### put majik awk script in /tmp/. ## extracts lines looking like:## 128.138.238.1 spot spot.colorado.edu## and spits things out that looks like:## HOSTNAME IN A nnn.nnn.nnn.nnn#cat << EOF > $AWKFILE/$INDOMAIN/ && \$1 ~ /[0-9]/ && \$1 !~ /#/ { i = 2 while( i <= NF) { if ( \$i == "#") { break } j = split(\$i,host,".") \$i = host[1] if ( length(host[1]) > 7 ) tab = "\t" else tab = "\t\t" printf("%s%sIN\tA\t%s\n",host[1],tab,\$1) ++i }}EOF### execute awk script. run /etc/hosts thru it.# should spit out all names and nicknames of hosts for a given domain.# filter it thru tr to get hostname in upper case, sort alphabetically# and uniq to drop duplicates #awk -f $AWKFILE < $HOSTSRC | sort | uniq > $HOSTFILE rm $AWKFILE##### take things like:## hostname IN A aaa.bbb.ccc.ddd## and turn them into things like:## ddd.ccc IN PTR hostname.Colorado.EDU#cat << EOF > $AWKFILE{ j = split(\$i,addr,".") printf("%s.%s\tIN\tPTR\t%s.%s.\n",addr[4],addr[3],\$1,"$OUTDOMAIN")}EOF### execute awk script. run /etc/hosts thru it.# should spit out all names and nicknames of hosts for a given domain.# strip -gateway and -gw, sort alphabetically and uniq to drop duplicates.#cat $HOSTFILE | \awk -f $AWKFILE | \sed -e 's/-gateway\./\./' -e 's/-gw\./\./' | sort | uniq > $REVFILErm $AWKFILE# forys' hack #1## make sure we don't have a dup entry for primary servers.set JEFHOSTS = ${HOSTFILE}.jefforeach Host ($PRIMEHOSTS) /bin/cp $HOSTFILE $JEFHOSTS /usr/bin/egrep -v "${Host}[ ]" $JEFHOSTS >$HOSTFILEend/bin/rm -f $JEFHOSTS# forys' hack #2## Add MX, HINFO & WKS records to HOSTFILE (if available)/usr/local/adm/hosts/tools/addhinfo $HOSTFILE####cat ./header.rev $REVFILE > ./named.revcat ./header.hosts $HOSTFILE > ./named.hosts### distribute to hosts running /etc/named#cat /dev/null > $ERRforeach host ( $PRIMEHOSTS ) $host "cp /etc/named.hosts /etc/named.hosts.previous; \ cp /etc/named.rev /etc/named.rev.previous" >& $TERR cat $TERR >> $ERR rcp ./named.hosts ./named.rev ${host}:/etc/ >& $TERR cat $TERR >> $ERR $host kill -HUP \`cat /etc/named.pid\` >& $TERR cat $TERR >> $ERR if ( !(-z $ERR)) then echo "Errors:" cat $ERR (echo "Errors:"; \ cat $ERR ) | \ /usr/ucb/mail -s "mkrevhosts: problems..." $NETADMIN rm $ERR rm $TERR endifendexit(0)### mail errors to NETADMIN and exit#mailexit: cat $TERR >> $ERR echo "Errors:" cat $ERR (echo "Errors:"; \ cat $ERR ) | \ /usr/ucb/mail -s "mkrevhosts: problems..." $NETADMIN rm $ERR rm $TERR exit(0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -