免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: king_819
打印 上一主题 下一主题

有奖专家座谈——自动化运维案例分享讨论之二(特邀某大型网游运维总监“king_819”) [复制链接]

论坛徽章:
0
61 [报告]
发表于 2011-12-26 14:12 |只看该作者
这个nagios就能做

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
62 [报告]
发表于 2011-12-26 15:37 |只看该作者
回复 57# king_819


/bin/cat /etc/rc.conf | grep ifconfig_lo0_alias1 | awk '{print $2}'
--->
awk '/ifconfig_lo0_alias1/{print $2}' /etc/rc.conf

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
63 [报告]
发表于 2011-12-26 15:40 |只看该作者
回复 57# king_819


netstat -an | grep $Squid3_IP | wc -l
--->
netstat -an | grep -c $Squid3_IP

论坛徽章:
0
64 [报告]
发表于 2011-12-26 15:53 |只看该作者
本帖最后由 king_819 于 2011-12-26 16:06 编辑

回复 62# Shell_HAT


    还是清野的写法简单,脚本已修改

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
65 [报告]
发表于 2011-12-28 16:05 |只看该作者
Demo_CPU.sh
  1. #!/bin/bash
  2. threshold=80
  3. cpuutil=`/usr/bin/top -n 1 | /bin/awk '/^Cpu/'`
  4. cpuused=`echo "${cpuutil}" | /bin/awk -F '[% ]+' '/^Cpu/{print int(100-$8)}'`
  5. if [ "${cpuused}" -ge "${threshold}" ]; then
  6.     echo "CPU utilization ${cpuused} is over ${threshold} percent"
  7.     #echo "${cpuutil}" | /bin/mailx -r "monitor@monitor.com" -s "Alert" "receiver@receiver.com"
  8. else
  9.     echo "CPU utilization ${cpuused} is under ${threshold} percent"
  10. fi
复制代码

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
66 [报告]
发表于 2011-12-28 16:05 |只看该作者
Demo_Memory.sh
  1. #!/bin/bash
  2. threshold=80
  3. process=mysql
  4. memoryutil=`/bin/ps aux | /bin/grep "^${process}"`
  5. memoryused=`echo "${memoryutil}" | /bin/awk '{print int($4)}'`
  6. if [ "${memoryused}" -ge "${threshold}" ]; then
  7.     echo "Memory utilization of ${process} ${memoryused} is over ${threshold} percent"
  8.     #echo "${memoryutil}" | /bin/mailx -r "monitor@monitor.com" -s "Alert" "receiver@receiver.com"
  9. else
  10.     echo "Memory utilization of ${process} ${memoryused} is under ${threshold} percent"
  11. fi
复制代码

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
67 [报告]
发表于 2011-12-28 16:06 |只看该作者
Demo_Disk.sh
  1. #!/bin/bash
  2. threshold=80
  3. diskutil=`/bin/df -h`
  4. for line in `echo "${diskutil}" | /bin/awk 'NR>1&&/%/{print $(NF-1)+0}'`; do
  5.     if [ "${line}" -ge "${threshold}" ]; then
  6.         echo "Disk utilization ${line} is over ${threshold} percent"
  7.         #echo "${diskutil}" | /bin/mailx -r "monitor@monitor.com" -s "Alert" "receiver@receiver.com"
  8.         break
  9.     else
  10.         echo "Disk utilization ${line} is under ${threshold} percent"
  11.     fi
  12. done
复制代码

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
68 [报告]
发表于 2011-12-28 16:07 |只看该作者
Demo_Password.sh
  1. #!/bin/bash
  2. threshold=5
  3. username=root
  4. passinfo=`/bin/grep "^${username}" /etc/shadow`
  5. lastchange=`echo "${username}" | /bin/awk -F: '/root/{print $3}'`
  6. max=`/bin/awk -F: '/root/{print $5}' /etc/shadow`
  7. today=`/usr/bin/perl -e 'printf "%5d\n", time()/3600/24'`
  8. let countdown=${lastchange}+${max}-${today}
  9. if [ "${countdown}" -le "${threshold}" ]; then
  10.     echo "${countdown}" -le "${threshold}"
  11.     echo "Password of ${username} will expire in $countdown days" | /bin/mailx -r "monitor@monitor.com" -s "Alert" "receiver@receiver.com"
  12. else
  13.     echo "${countdown}" -gt "${threshold}"
  14. fi
复制代码

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
69 [报告]
发表于 2011-12-28 16:08 |只看该作者
Demo_Singleton.sh
  1. #!/bin/bash

  2. #Singleton check
  3. scriptname=$(basename $0)
  4. pidfile=$scriptname.pid
  5. single=1
  6. if [ -e "$pidfile" ]; then
  7.     read pidlast < "$pidfile"
  8.     scriptlast=$(ps -ef | grep "\<$pidlast\>.*/$scriptname\>" | grep -v "grep" | awk -F/ '{print $NF}')
  9.     if [ "$scriptlast" == "$scriptname" ]; then
  10.         single=0
  11.     fi
  12. fi
  13. if [ "$single" == "1" ]; then
  14.     echo $ > "$pidfile"
  15.     echo "Green light to run"
  16. else
  17.     echo "Duplicate instance detected"
  18.     exit 1
  19. fi

  20. #Script body
  21. sleep 1000
复制代码

论坛徽章:
2
CU大牛徽章
日期:2013-04-17 11:46:28CU大牛徽章
日期:2013-04-17 11:46:39
70 [报告]
发表于 2011-12-28 17:06 |只看该作者
不错不错~!学习
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP