Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement one-click installation of Shell script in SNMP under Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to implement the Shell script of one-click installation of SNMP under Linux, which is very detailed and has certain reference value. Interested friends must read it!

Net-SNMP is a free, open source SNMP implementation formerly known as UCD-SNMP. After installation, many SNMP are used as the monitoring treasure and the system information monitoring of Aliyun.

#! / usr/bin/env bash export LC_ALL=C if ["$(id-u)"! = "0"] then echo "This script. Must be run as root "1 > & 2 exit 1 fi####check if gcc perl perl-devel (centos) or libperl-dev (ubuntu) exists APT_CMD= where apt-get | awk'{print $2} '`YUM_CMD= where yum | awk' {print $2} '`if ["$APT_CMD" x! = "x] then echo" $APT_CMD "cmd= `dpkg-l | grep gcc`if [" $cmd "x ="x] then apt-get install-y gcc fi cmd= `dpkg-l | grep perl`if [" $cmd "x ="x] then apt-get install-y perl fi cmd= `dpkg- L | grep "libperl-dev" `if ["$cmd" x = "x] then apt-get install-y libperl-dev fi elif [" $YUM_CMD "x! ="x] then echo $YUM_CMD cmd= `rpm-Q gcc | grep-v" not installed "`if [" $cmd "x ="x] then yum install gcc-y 1 > / dev/null 2 > & 1 fi cmd= `rpm-Q perl | grep-v" not installed "`if [" $cmd "x =" x] then yum install-y perl 1 > / dev/null 2 > & 1 fi cmd= `rpm-Q perl-devel | grep-v "not installed" `if ["$cmd" x = "" x] then yum install-y perl-devel 1 > / devel/null 2 > & 1 fi else echo "your release have no yum or apt-get" fi function Usage () {echo "usage is as follows: (note: version 2C password must be greater than 6 characters. Version 3 password must be greater than 8 digits) " Echo "" echo "$0-v version number (2 for 2C lt 3 for version 3)-u username-p password"; echo "$0-v [2 | 3]-u username-p password"; echo "; exit 0;} if [$#-lt 1] then echo" Please enter the parameter "Usage fi#get parameters version=0 username="password="while getopts": v:u:p: "opt" Do case $opt in v) version=$OPTARG if [[${OPTARG:0:1} = "-"] then echo "" echo "- v need argument" echo "" Usage fi " U) username=$OPTARG if [[${OPTARG:0:1} = "-"]] then echo "echo"-u need argument "echo"Usage fi" P) password=$OPTARG if [[${OPTARG:0:1} = "-"] then echo "" echo "- p need argument" echo "" Usage fi;;:) Usage;;?) Paralist=-1; Usage Esac done # check version number, must be 2 or 3 if [$version-ne "3"-a $version-ne "2"] then Usage exit 3 fi if [$version-eq "3"-a "$username" x = "x] then echo version 3 must enter the user name" Usage fi###check password length, version 3 big then 8 " Version 2 big then 6 if ["$version"-eq "3"] then if [${# password}-lt "8"] then echo "" echo "Your passwords must greater than 8 bytes" 1 > & 2 echo "" Usage fi else # version = 2 if [${# password}-lt "6"] then echo "" echo "Your passwords must greater than 6 bytes "1 > & 2 echo" Usage fi fi wget http://download.cloud.360.cn/yjk/net-snmp.tar.gz tar zxvf net-snmp.tar.gz cd net-snmp-5.7.2. / configure-- prefix=/usr/local/snmp-- with-mib-modules=ucd-snmp/diskio-enable-mfd-rewrites-- with-default-snmp-version= "$version"-- with-sys-contact= "@ @ no.where"-- with-sys- Location= "Unknown"-- with-logfile= "/ var/log/snmpd.log"-- with-persistent-directory= "/ var/net-snmp" make make install case $version in 2) cat > > / usr/local/snmp/share/snmp/snmpd.conf > / usr/local/snmp/share/snmp/snmpd.conf > / var/net-snmp/snmpd.conf# cat > > / var/net-snmp/snmpd.conf & 2 echo exit 1 ; esac iTun0 while [$I-lt 5] do ret= `/ usr/local/snmp/sbin/ snmpd` ret= `ps aux | grep-v grep | grep snmp` if ["$ret" x = "" x] then ((i=i+1)) ret=` / usr/local/snmp/sbin/ snmpd` else break fi done case $version in 3) echo "createUser $username MD5 $password" > > / var/net-snmp/snmpd.conf Esac pid= `ps-ef | grep snmpd | grep-v grep | awk'{print $2} '`echo "pid: $pid" if ["$pid" x! = "" x] then kill-9$ pid / usr/local/snmp/sbin/snmpd else / usr/local/snmp/sbin/snmpd fi case $version in 3) cmd= `cat / var/net-snmp/snmpd.conf | grep "$username" `if ["$cmd" x = "x] then pid= `ps-ef | grep snmpd | grep-v grep | awk' {print $2} '`if ["$pid" x! = "x] then kill-9$ pid echo" createUser $username MD5 $password "> > / var/net-snmp/snmpd.conf fi fi ; esac ret= `ps-ef | grep-v grep | grep snmp`if ["$ret" x! = "" x] then echo "snmp start success" echo else echo "snmp start failed" echo exit 4 fi echo "Finish..." Echo exit 0 and above are all the contents of this article entitled "how to install Shell script with one click on SNMP under Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report