日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux监控脚本

發(fā)布時間:2025/3/17 linux 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux监控脚本 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1,snmp安裝腳本for ubuntu/CentOS

#!/usr/bin/env bashexport LC_ALL=Cif [ "$(id -u)" != "0" ]thenecho "This script. must be run as root" 1>&2exit 1fi ####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 ]thenecho "$APT_CMD"cmd=`dpkg -l|grep gcc`if [ "$cmd"x = ""x ]thenapt-get install -y gcc ficmd=`dpkg -l|grep perl`if [ "$cmd"x = ""x ]thenapt-get install -y perl ficmd=`dpkg -l|grep "libperl-dev"`if [ "$cmd"x = ""x ]thenapt-get install -y libperl-dev fielif [ "$YUM_CMD"x != ""x ]thenecho $YUM_CMDcmd=`rpm -q gcc|grep -v "not installed"`if [ "$cmd"x = ""x ]thenyum install gcc -y 1>/dev/null 2>&1ficmd=`rpm -q perl|grep -v "not installed"`if [ "$cmd"x = ""x ]thenyum install -y perl 1>/dev/null 2>&1ficmd=`rpm -q perl-devel|grep -v "not installed"`if [ "$cmd"x = ""x ]thenyum install -y perl-devel 1>/devel/null 2>&1fielseecho "your release have no yum or apt-get"fifunction 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 ]thenecho "請輸入?yún)?shù)"Usagefi #####get parametersversion=0username=""password=""while getopts ":v:u:p:" opt;docase $opt inv)version=$OPTARGif [[ ${OPTARG:0:1} = "-" ]]thenecho ""echo "-v need argument"echo ""Usagefi;;u)username=$OPTARGif [[ ${OPTARG:0:1} = "-" ]]thenecho ""echo "-u need argument"echo ""Usagefi;;p)password=$OPTARGif [[ ${OPTARG:0:1} = "-" ]]thenecho ""echo "-p need argument"echo ""Usagefi;;:)Usage;;?) paralist=-1;Usage;;esacdone ###check version number, must be 2 or 3if [ $version -ne "3" -a $version -ne "2" ]thenUsageexit 3fiif [ $version -eq "3" -a "$username"x = ""x ]thenecho "版本3必須要輸入用戶名"Usagefi ###check password length, version 3 big then 8, version 2 big then 6if [ "$version" -eq "3" ] thenif [ ${#password} -lt "8" ]thenecho ""echo "Your passwords must greater than 8 bytes" 1>&2echo ""Usagefielse ########### version = 2if [ ${#password} -lt "6" ]thenecho ""echo "Your passwords must greater than 6 bytes" 1>&2echo ""Usagefifiwget http://download.cloud.360.cn/yjk/net-snmp.tar.gztar zxvf net-snmp.tar.gzcd 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"makemake installcase $version in2)cat >> /usr/local/snmp/share/snmp/snmpd.conf << EOF rocommunity $password 101.199.100.150 rocommunity $password 220.181.150.98 rocommunity $password 180.153.229.230 rocommunity $password 220.181.150.125 rocommunity $password 103.28.10.223 EOF;;3)cat >> /usr/local/snmp/share/snmp/snmpd.conf << EOF rouser $username auth EOF # 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>&2echoexit 1;;esaci=0while [ $i -lt 5 ]doret=`/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`elsebreakfidonecase $version in3)echo "createUser $username MD5 $password" >>/var/net-snmp/snmpd.conf;;esacpid=`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/snmpdelse/usr/local/snmp/sbin/snmpdfi case $version in3)cmd=`cat /var/net-snmp/snmpd.conf|grep "$username"`if [ "$cmd"x == ""x ]thenpid=`ps -ef|grep snmpd|grep -v grep|awk '{print $2}'`if [ "$pid"x != ""x ]thenkill -9 $pidecho "createUser $username MD5 $password" >>/var/net-snmp/snmpd.conffifi;;esacret=`ps -ef | grep -v grep | grep snmp`if [ "$ret"x != ""x ]thenecho "snmp start success"echoelseecho "snmp start failed"echoexit 4fiecho "Finish..."echoexit 0 View Code

?

總結(jié)

以上是生活随笔為你收集整理的linux监控脚本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。