Chinaunix首页 | 论坛 | 博客
  • 博客访问: 66167
  • 博文数量: 21
  • 博客积分: 100
  • 博客等级: 民兵
  • 技术积分: 273
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-30 09:56
文章分类

全部博文(21)

文章存档

2013年(18)

2012年(3)

我的朋友

分类: LINUX

2013-08-08 20:17:26


  1. 一、包含文件说明
  2. 1、(addmac.sh) 为添加MAC脚本。
  3. 2、(reserv.sh) 为重启VMPS服务脚本。
  4. 3、(vlanname) 为网络中存在的vlanname列表。
  5. 4、(vmpsd.log)为添加MAC输出LOG。
  6. 5、(volumelis)为批量添加MAC列表。
  7. 6、(volumeadd.sh)为批量添加MAC脚本。
  8. 7、 (chklog.sh) 查看log,主要用于查看MAC地址冲突
  9. 8、(chkpc.sh) 每天备份log信息
  10. 二、使用说明
  11. 1、单MAC地址添加使用./addmac.sh
  12. # 查看使用说明
  13. 2、批量加添使用./volumeadd.sh
  14. # 注意volumeadd列表格式:XX-XX-XX-XX vlanname zhushi
  15. 3、chklog.sh用法
  16. ./chklog.sh 1000 xx:xx:xx:xx:xx
  17.                 ^ ^-------------
  18.           查看最近1000行log     ||
  19.                              MAC地址

点击(此处)折叠或打开

  1. #cat AddMac.sh
  2. #!/bin/bash
  3. ########################################
  4. # The: JiangFeng.Cai
  5. # From: baustem
  6. # date: 2010-12-16
  7. # Thanks
  8. ########################################
  9. echo '***************************************'
  10. echo '1.This script is add MAC to vmpsd server.'
  11. echo '2.Log name vmpsd.log.'
  12. echo '3.Reserved vlans name list ./vlanname.'
  13. echo '4.Backup dir ./vlanbackup.'
  14. echo '5 Add to replace the existing MAC address.2013-03-27'
  15. echo '***************************************'
  16. echo "uasge: $0 "
  17. echo 'MACadd format: ****.****.****'
  18. echo '***************************************'
  19. echo ''
  20. changemac () {
  21. mac=`echo $mac|sed -e 's/\.//g' -e 's/$//g' -e 's/\t/ /g' -e 's/://g' -e 's/-//g' -e 's/\(....\)\(....\)\(....\)/\1.\2.\3/' -e 'y/ABCDEF/abcdef/'`
  22. }
  23. check () {
  24. echo ${mac} |grep -q '\w\{4,\}\.\w\{4,\}\.\w\{4,\}'
  25. if [ ! $? -eq 0 ];then
  26. echo '#################################'
  27. echo 'Enter error MAC!!'
  28. echo 'MACadd format: ****.****.****'
  29. echo '#################################'
  30. exit 1
  31. fi
  32. cat ${vlandb_data}|grep -q ${mac}
  33. if [ $? -eq 0 ];then
  34. echo '###############################'
  35. echo '# Input MACadd exist!'
  36. echo '###############################'
  37. echo ''
  38. echo -n 'Do you want to replace the Mac?(Yes/No):'
  39. read yn
  40. case $yn in
  41. [Yy][Ee][Ss] |[Yy] ) sed -i "/${mac}/d" $vlandb_data
  42. ;;
  43. [Nn][Oo] |[Nn] ) echo ''
  44. echo 'exit addmac.'
  45. exit 4
  46. ;;
  47. * ) exit 5
  48. ;;
  49. esac
  50. fi
  51. [ -f ${path}/vlanname ] || touch ${path}/vlanname
  52. cat ${path}/vlanname | grep -q ${vlanname}
  53. if [ ! $? -eq 0 ];then
  54. echo '#######################'
  55. echo 'vlanname not exist!!'
  56. echo 'Format: vlanname1'
  57. echo ' vlanname2'
  58. echo ' vlanname{n}'
  59. echo 'Reserved vlans name:'
  60. cat ${path}/vlanname
  61. echo '#######################'
  62. exit 3
  63. fi
  64. }
  65. # addmac
  66. addmac () {
  67. [ -d ${vlanbackup} ] || mkdir ${vlanbackup}
  68. cd ${vlandb_path}
  69. tar -czf ${vlanbackup}/vlandb${backtime}.tar.gz vlan.db
  70. cd ${path}
  71. if [ ${var} -eq 2 ];then
  72. sed 23a\ "address ${mac} vlan-name ${vlanname}" ${vlandb_data} > ${path}/vlan.db
  73. fi
  74. if [ ${var} -eq 3 ];then
  75. sed 23a\ "address ${mac} vlan-name ${vlanname}" ${vlandb_data}|sed 23a\ "! ${xingming}" > ${path}/vlan.db
  76. fi
  77. rm -rf ${vlandb_data}
  78. mv ${path}/vlan.db ${vlandb_path}
  79. echo "!-------------------${xingming}----------------" >> ${vmpsdlog}
  80. echo "${backuptime}" >> ${vmpsdlog}
  81. echo "address ${mac} vlan-name ${vlanname}" >> ${vmpsdlog}
  82. echo ''
  83. }
  84. # restart vmpsd service
  85. revmpsd () {
  86. ${vmpsd}
  87. kill -9 ${vmpsdid}
  88. ${vmpsd}
  89. }
  90. # ok let's begin {
  91. #set variable
  92. mac=$1
  93. var=$#
  94. vlanname=$2
  95. xingming=$3
  96. path=`pwd`
  97. vmpsd=/usr/local/bin/vmpsd
  98. vmpsdlog=${path}/vmpsd.log
  99. vmpsdid=`ps aux|grep vmps|grep -v 'grep'|awk '{print $2}'`
  100. backtime=`date +%Y-%m-%d-%H%M%S`
  101. vlanbackup=${path}/vlanbackup
  102. vlandb_path=/usr/local/etc/
  103. vlandb_data=/usr/local/etc/vlan.db
  104. # check variable
  105. if [ $# -eq 0 ];then
  106. echo '####################################'
  107. echo 'Error enter!!!'
  108. echo "uasge: $0 "
  109. echo 'MACadd format: ****.****.****'
  110. echo '####################################'
  111. exit 100
  112. fi
  113. #change mac
  114. changemac
  115. # runing check input
  116. check
  117. # runing addmac
  118. addmac
  119. # runing revmpsd service
  120. #revmpsd
  121. if [ $? -eq 0 ];then
  122. echo '**************************'
  123. echo 'Address MAC done.'
  124. echo "MAC: ${mac}"
  125. echo "Vlanname: ${vlanname}"
  126. echo '**************************'
  127. fi
  128. #The end }


点击(此处)折叠或打开

  1. #reserv.sh
  2. #!/bin/bash
  3. ########################################
  4. # The: JiangFeng.Cai
  5. # From: baustem
  6. # date: 2010-12-16
  7. # Thanks
  8. ########################################
  9. vmserv=`ps aux|grep [v]mpsd|awk '{print $2}'`
  10. if [ $? -eq 0 ];then
  11. kill -9 ${vmserv}
  12. /usr/local/bin/vmpsd
  13. else
  14. /usr/local/bin/vmpsd
  15. fi
  16. exit 0


点击(此处)折叠或打开

  1. #volumeadd.sh
  2. #!/bin/bash
  3. ###########################
  4. #The:JiangFeng.Cai
  5. #Date:2010-12-16
  6. #From:BeiJing Baustem
  7. ###########################
  8. path=`pwd`
  9. i=1
  10. vo=${path}/volumelis
  11. vo1=${path}/volume1
  12. vo2=${path}/volume2
  13. vlanconf=/usr/local/etc/vlan.db
  14. [ -f ${vo} ] || touch ${vo}
  15. dos2unix ${vo}
  16. sed -e 's/$//g' -e 's/\t/ /g' -e 's/-//g' -e 's/\(....\)\(....\)\(....\)/\1.\2.\3/' -e 'y/ABCDEF/abcdef/' ${vo} > ${vo1}
  17. hs=`sed -n '$=' ${vo1}`
  18. if [ $? -eq 0 ];then
  19. while [[ ${i} -le ${hs} ]]
  20. do
  21. mac=`sed -n ${i}p ${vo1}|awk '{print $1}'`
  22. vlan=`sed -n ${i}p ${vo1}|awk '{print $2}'`
  23. xingming=`sed -n ${i}p ${vo1}|awk '{print $3}'`
  24. ./addmac.sh ${mac} ${vlan} ${xingming}
  25. echo ${i}
  26. ((i++))
  27. done
  28. fi
  29. rm -fr ${vo1}
  30. dos2unix ${vlanconf}


点击(此处)折叠或打开

  1. #cat chklog.sh
  2. #!/bin/bash
  3. log=/var/log/messages
  4. if [ $# -eq 1 ];then
  5. hang=$1
  6. cat ${log}|grep 'vmpsd:'|tail -${hang}
  7. fi
  8. if [ $# -eq 2 ];then
  9. hang=$1
  10. mac=$2
  11. cat /var/log/messages|grep 'vmpsd:'|tail -"${hang}"|grep "$mac"
  12. fi

点击(此处)折叠或打开

  1. #cat chkpc.sh
  2. #!/bin/bash
  3. ########################################
  4. # The: JiangFeng.Cai
  5. # From: baustem
  6. # date: 2011-3-1
  7. # Thanks
  8. ########################################
  9. # var
  10. yue=`date -d '1 day ago' +%m`
  11. days=`date -d '1 day ago' +%d`
  12. day=`expr ${days} + 0`
  13. mday=`date -d '1 day ago' +%Y%m%d`
  14. logfile=/var/log/messages
  15. rizhi=/vmpsd/rizhi/
  16. case ${yue} in
  17. 01) m=Jan
  18. ;;
  19. 02) m=Feb
  20. ;;
  21. 03) m=Mar
  22. ;;
  23. 04) m=Apr
  24. ;;
  25. 05) m=May
  26. ;;
  27. 06) m=June
  28. ;;
  29. 07) m=July
  30. ;;
  31. 08) m=Aug
  32. ;;
  33. 09) m=Sept
  34. ;;
  35. 10) m=Oct
  36. ;;
  37. 11) m=Nov
  38. ;;
  39. 12) m=Dec
  40. ;;
  41. esac
  42. grep "${m} *${day}.*vmpsd:" ${logfile} |sed 's/\(..\)\:\(..\)\:\(..\)\:\(..\)\:\(..\)\:\(..\)/\1-\2-\3-\4-\5-\6/g' > \
  43. ${rizhi}${mday}.vmps


阅读(2201) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~