麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發 > Linux Shell > 正文

Linux下實現SNMP一鍵安裝的Shell腳本

2020-07-27 19:15:23
字體:
來源:轉載
供稿:網友

Net-SNMP是一個免費的、開放源碼的SNMP實現,以前稱為UCD-SNMP。SNMP 很多都用其安裝之后,作為監控寶和阿里云的系統信息監控使用。下面就來分享linux下實現SNMP一鍵安裝的shell腳本:

#!/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=`whereis apt-get|awk '{print $2}'`  YUM_CMD=`whereis 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 "用法如下:(注意:2c版本密碼必須大于6位,3版本密碼必須大于8位)";    echo ""    echo "  $0 -v 版本號(2代表2C,3代表版本3) -u 用戶名 -p 密碼";    echo "  $0 -v [2|3] -u username -p password";    echo "";    exit 0; } if [ $# -lt 1 ] then   echo "請輸入參數"   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 "版本3必須要輸入用戶名"   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 << EOFrocommunity $password 101.199.100.150rocommunity $password 220.181.150.98rocommunity $password 180.153.229.230rocommunity $password 220.181.150.125rocommunity $password 103.28.10.223EOF   ;;   3)   cat >> /usr/local/snmp/share/snmp/snmpd.conf << EOFrouser $username authEOF#   echo "createUser $2 MD5 $3" >>/var/net-snmp/snmpd.conf#   cat >> /var/net-snmp/snmpd.conf << EOF#createUser $2 MD5 $3#EOF   ;;   *)   echo "Please check your input version" 1>&2   echo   exit 1   ;;  esac i=0 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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美亚洲一区二区三区四区 | 草莓福利视频在线观看 | 欧美日韩亚洲在线 | 综合国产在线 | 久久精品视频黄色 | 中文字幕在线第二页 | 色综合狠狠 | 国产色爱综合网 | 96视频在线免费观看 | 日美av在线 | 久久久免费 | 2级毛片| 亚洲综合色视频在线观看 | 国产中出在线观看 | 国产午夜精品视频免费不卡69堂 | 国产高潮好爽好大受不了了 | 视频一区二区在线播放 | 色屁屁xxxxⅹ在线视频 | 亚洲一区二区免费 | 久久亚洲春色中文字幕久久 | 欧美视频在线观看一区 | 九九视屏 | 亚洲va久久久噜噜噜久牛牛影视 | 国产亚洲综合一区二区 | 色七七久久影院 | 久久久国产精品网站 | 亚洲国产超高清a毛毛片 | 国产羞羞网站 | 性欧美大战久久久久久久免费观看 | 成人午夜在线免费观看 | 国产成人综合在线视频 | 黄视频免费在线观看 | 午夜视频在线免费播放 | 日本精品视频一区二区三区四区 | 久久免费视频8 | 在线看免费观看av | 欧美a视频在线观看 | 国产一区网址 | 国产一区毛片 | 成人福利软件 | 国产乱淫a∨片免费观看 |