snmpsetup.sh

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· Shell 代码 · 共 566 行

SH
566
字号
#! /bin/sh# @(#)snmpsetup.sh	4.2	(ULTRIX)	9/11/90#									# 			Copyright (c) 1989 by# 		Digital Equipment Corporation, Maynard, MA		# 			All rights reserved.				# 									#    This software is furnished under a license and may be used and	#    copied  only  in accordance with the terms of such license and	#    with the  inclusion  of  the  above  copyright  notice.   This	#    software  or  any  other copies thereof may not be provided or	#    otherwise made available to any other person.  No title to and	#    ownership of the software is hereby transferred.			# 									#    The information in this software is subject to change  without	#    notice  and should not be construed as a commitment by Digital	#    Equipment Corporation.						# 									#    Digital assumes no responsibility for the use  or  reliability	#    of its software on equipment which is not supplied by Digital.	## Purpose:	Set up Simple Network Management (SNMP)# Usage:	snmpsetup# Environment:	Bourne shell script# # Remarks:	Sets up files:#		/etc/rc#		/etc/snmpd.conf### Modification History:## 06/01/89	R. Bhanukitsiri#		Initial Release.## 09/10/90      Mary Walker#		added in more vericationsECHO="/bin/echo -n"## Default files location#keep=ncase $1 in debug)	shift	DEBUG=1	RC=/tmp/rc	CONF=/tmp/snmpd.conf	echo "snmpsetup running in DEBUG mode ..."	if [ -r /etc/rc ]		then		cp /etc/rc $RC	else		echo "snmpsetup: need /etc/rc"		exit 1	fi	if [ -r /etc/snmpd.conf ]		then		cp /etc/snmpd.conf $CONF	else		echo "snmpsetup: need /etc/snmpd.conf"		exit 1	fi	;; keep)	shift	keep="y"	RC=/etc/rc	CONF=/etc/snmpd.conf	;; *)	keep="n"	RC=/etc/rc	CONF=/etc/snmpd.conf	;;esacecho "			***** SNMPSETUP *****"## snmpsetup must be run by root#if [ \! -w $RC ]	then	echo "snmpsetup: must be run by root."	exit 1fiif [ `whoami` != root ]	then	echo "snmpsetup: must be run by root."	exit 1fi## Default working file locations#RCTMP=/tmp/snmpd.rc.$$.tmpCONFTMP=/tmp/snmpd.conf.$$.tmpSYSTMP=/tmp/snmpd.sys.$$.tmpINTFTMP=/tmp/snmpd.intf.$$.tmpNULL=/dev/null## define symbols#sysDescr=ifName=## Set up interrupt handlers:#QUIT='	if [ "$keep" = "n" ]		then		for i in $RCTMP $CONFTMP $SYSTMP $INTFTMP		do 			if [ -r $i ]				then				rm $i			fi		done	fi	echo "snmpsetup: terminated with no installations made."	echo	exit 1'## Trap ^C signal, etc.#trap 'eval "$QUIT"' 1 2 3 15## Gather system MIB default configuration#mach=`/bin/machine`if [ "$mach" = "mips" ]	then	dbx -k /vmunix /dev/mem > $SYSTMP << EOFprint versionprint cpuquitEOF	# read	vers=	cpu=else	adb -k /vmunix /dev/mem > $SYSTMP << EOF_version/s_cpu/XquitEOF	# read	vers=	cpu=fisysDescr="`/bin/hostname`:$cpu:$vers"## Create default configuration file#if [ -f $CONFTMP ]	then	rm -f $CONFTMPficat $CONF | while read field1 linedo	if [ "$field1" = "#" ]		then		echo "$field1 $line" >> $CONFTMP	fidone## Gather interface MIB default configuration#netstat -i > $INTFTMPcat $INTFTMP | while read ifndo	ifName=`echo $ifn | awk '{ print substr($1,0,2) }'`done## Determine run-time mode.#if [ -n "$1" ]	then	echo "snmpsetup: non-interactive mode not currently supported."	exit 1fi## Be sure network has already been set up, and this host has a name!#host=`hostname`if [ $? -ne 0 ]then	echo "snmpsetup: network must be setup before running snmpsetup."	eval "$QUIT"fiecho "The snmpsetup command configures the SNMP Network Management Agentfor  your  system.  SNMP is  a  network  management  protocol thatenables your system to be managed by the network manager.The snmpsetup command first displays the  default configuration databaseand allows you to tailor the configuration database to suit your system.Default answers  are  shown  in  square brackets ([]).  To use a defaultanswer, press the RETURN key.Note:	snmpsetup command  modifies the /etc/snmpd.conf file."$ECHO "[ Press the RETURN key to continue ]: "read junk## System MIB configuration#echo "The ULTRIX sysDescr contains three fields separated by a ":".  Thesefields are:	host-name:hardware-description:software-descriptionThis is your default system description (sysDescr):	$sysDescr"$ECHO "Do you wish to change your system description (sysDescr) [n]? "read anscase $ans in [yY]*)echo "System description string that you enter must not be separated byany blank space(s)."	again=y	while [ $again ]	do		$ECHO "Enter new sysDescr? "		read sysDescr		if [ "$sysDescr" = "" ]			then			continue		fi		set `echo $sysDescr`		if [ "$2" != "" ]			# check for blanks			then			echo "sysDescr contains blank space(s), please retry"			continue		fi		$ECHO "Your sysDescr is: $sysDescr.  Is this correct [y]? "		read ans		case $ans in		  [yY]*|"")echo "sysDescr	$sysDescr" >> $CONFTMP			  again=""			  ;;		  [nN]*)again=y			;;		 *)	again=y		esac	done	;; [nN]*)	break;; *)	break;;esac## Interface configuration#echo "The following network interfaces, if present, will be automaticallyconfigured by the SNMP Network Management Agent:	de ln lo ni qe scs xna.If you have network interfaces, not shown on this list, you mustconfigure them manually.   The following  network interfaces arecurrently present on your system:"$ECHO "	"cat $INTFTMP | while read ifndo	ifName=`echo $ifn | awk '{ print $1}'`	if [ "$ifName" != "Name" ]		then		$ECHO "$ifName "	fidoneecho ""$ECHO "Do you wish to add network interfaces [n]? "read anscase $ans in [yY]*)echo >> $CONFTMP	again=y	while [ $again ]	do		$ECHO "Enter new interface name (ifName)? "		read ifName		$ECHO "Enter interface type (ifType) [6]? "		read ifType		if [ "$ifType" = "" ]			then			ifType=6		fi		$ECHO "Enter interface speed (ifSpeed) [10000000]? "		read ifSpeed		if [ "$ifSpeed" = "" ]			then			ifSpeed=10000000		fi		echo		echo "You have entered: ifName=$ifName ifType=$ifType ifSpeed=$ifSpeed."		$ECHO "Is this correct [y]? "		read ans		case $ans in		 [yY]*|"")echo "interface	$ifName type $ifType" >> $CONFTMP			echo "interface	$ifName speed $ifSpeed" >> $CONFTMP			again=""			;;		 [nN])	again=y			;;		 *)	again=y		esac		echo		if [ "$again" = "" ]			then			$ECHO "Do you wish to add another network interface [n]? "			read ans			case $ans in			 [yY]*|"") again=y  ;;			 [nN]*)	   again="" ;;			 *)	   again="" ;;			esac		fi	done	;; [nN]*)break;; *)	break;;esac## Community configuration#echo "A  community name  is used by the SNMP protocol to authenticate requestfrom a network manager.  A  community  can be read-only, read-write, ortraps.  If  a community  is read-write,  the network manager can affectthe  behavior of the network on your host. Your system can be monitoredby any network manager  if the IP address associated with the communityis 0.0.0.0.  For example,		community	public 0.0.0.0 read-onlyThe community information is mandatory and must be configured."echo >> $CONFTMPpub=fagain=ywhile [ $again ]do	$ECHO "Enter community name [RETURN when done]? "	read comm	if [ "$comm" = "" ]		then		break	fi	$ECHO "Enter IP address associated with community $comm [0.0.0.0]? "	read ipaddr	if [ "$ipaddr" = "" ]		then		ipaddr="0.0.0.0"	fi	$ECHO "Select community type (read-only,read-write,traps) [read-only]? "	read commtype	case $commtype in	 read-only)	;;	 read-write)	;;	 *)		commtype="read-only" ;;	esac	echo "community	$comm	$ipaddr	$commtype" >> $CONFTMP	echo	if [ $comm = public -a $ipaddr = 0.0.0.0 -a $commtype = read-only ]		then		pub=t	fi	again=y	while [ $again ]	do		$ECHO "Do you wish to add another community [n]? "		read ans		case $ans in		 [yY]*)again=y  ;;		 [nN]*|"")again="" ;;		 *)	again="" ;;		esac	donedoneechoegrep -s community $CONFTMPif [ $? = 1 ]	then	echo "You have not configured any community.  Without a community, the SNMPNetwork Management will NOT respond to any network management requestfrom anyone."fiif [ $pub = f ]	then	echo "A public community accessible by ANYONE can be configured for you as:	community 	public	0.0.0.0	read-onlyWe caution you that this means readable by ANYONE!"	again=y	while [ $again ]	do		$ECHO "Do you wish to proceed to add the public community [y]? "		read ans		case $ans in		 [yY]*|"")echo "community	public	0.0.0.0	read-only" >> $CONFTMP			again=""			;;		 [nN]*)again="" ;;		 *)	again=y ;;		esac	doneelse	echo "A public community accessible by ANYONE was configured by you as:	community 	public	0.0.0.0	read-onlyWe caution you that this means readable by ANYONE!"fi## Extensible Agent configuration#echo "ULTRIX extends the capability of the SNMP Network Management Agentwith  extensible agents.  An  extensible agent is  usually a user-written daemon that  provides more  network management  capabilityspecific to the user."again=ywhile [ $again ]do	$ECHO "Do you wish to include a user-written extended agent [n]? "	read ans	case $ans in	 [yY]*)    ext_agent=y; again="" ;;	 [nN]*|"") ext_agent=""; again="";;	 *)        ext_agent=""; again=y ;;	esacdoneecho >> $CONFTMPwhile [ $ext_agent ]do	$ECHO "Enter full path name of the extended agent? "	read eapath	if [ "$eapath" = "" ]		then		continue	fi	def_eaname=`echo $eapath | awk -F/ '{ print $NF}'`	$ECHO "Enter name of the extended agent [$def_eaname]? "	read eaname	if [ "$eaname" = "" ]		then		eaname=$def_eaname	fi	echo	again=y	while [ $again ]	do		echo  "You have entered: path=$eapath name=$eaname."		$ECHO "Is this correct [y]? "		read ans		case $ans in		 [yY]*|"")ext_agent=""; again="" ;;		 [nN]*) ext_agent=y; again="" ;;		 *)	again=y ;;		esac	done	echo "extension	$eapath	$eaname" >> $CONFTMP	echo	if [ "$ext_agent" = "" ]	then		again=y		while [ $again ]		do			$ECHO "Do you wish to include another extended agent [n]? "			read ans			case $ans in			 [yY]*)   ext_agent=y; again="" ;;			 [nN]*|"")ext_agent=""; again="" ;;			 *)	again=y ;;			esac		done	fidone## Add /etc/snmpd to /etc/rc if not defined.#egrep -s "snmpd" $RCif [ $? = 1 ]	then	cp $RC $RCTMP	ed $RCTMP > $NULL << EOF/inetd/}.+1i[ -f /etc/snmpd ] && {	/etc/snmpd;		echo -n ' snmpd'		>/dev/console}.wqEOFfi## Update the system files#if [ -r $RCTMP ]	then	mv $RCTMP $RCfimv $CONFTMP $CONF## Cleanup.#if [ "$keep" = "n" ]	then	for i in $RCTMP $CONFTMP $SYSTMP $INTFTMP	do 		if [ -r $i ]			then			rm $i		fi	donefi## All done.#echoecho "		***** SNMPSETUP COMPLETE *****"exit 0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?