linux监控脚本
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 "請輸入參數"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?
總結
- 上一篇: 【黑金原创教程】【FPGA那些事儿-驱动
- 下一篇: 转:LruCache算法