资源描述:
《几个常用的linux操作系统监控脚本》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、几个常用的Linux操作系统监控脚本:1、查看主机网卡流虽井!/bin/bash^network#Mike.Xuwhile::dotime=,date+%nT-"%cTday=,date+%nT-"%d’rx_before=,ifconfigethO
2、sed-n"8"p
3、awk’{printS2}>
4、cut-c7-’tx_bcfore=,ifconfigethO
5、scd-n"8"p
6、awk’{print$6}’
7、cut-c7-’sleep2rx—after:’ifconfigethO
8、sed-n"8"p
9、awk’{printS2},
10、cut-c7-
11、’tx_after=,ifconfigethO
12、sed-nVp
13、awk’{print$6}’
14、cut-cl-rx_result=$[(rx_after-rx_before)/256]tx_result=$[(tx_after-tx_bcfore)/2.56]echoNow_In_Spced:〃$rx_result"kbpsNow_OUt_Spced:〃Stx_result〃kbps〃sleep2done2、系统状况监控#!/bin/sh#systemstat.sh#Mike.XuIP=192.168.1.227top-n2
15、grep"Cpu"》
16、./temp/cpu.txtfree-m
17、grcp"MenT》./temp/mem.txtdf-k
18、grep"sdal"》./temp/drive_sdal.txt#df-k
19、grepsda2》./temp/drive_sda2.txtdf-kgrep"/mnt/storagejT〉〉./temp/mnt_storage_0.txtdf-k
20、grepVmnt/storage_pic"》./1emp/nuit_storage_pic.txttime=late+%m"."%d"connect='netstat-nagrep"219.238.148.30:8
21、0〃wc-Techo"Stime$connect"》•/temp/connectcount,txt3、监控主机的磁盘空间,当使用空间超过90%就通过发mMl来发羚告#!/bin/bash^monitoravailablediskspaceSPACE二’df
22、sed-n’//$/p’
23、gawk’{print$5}’
24、sed’s/%//’if[$SPACE-ge90]thenfty89@163.comfi4、监拧CPU和内存的使用怙况#!/bin/bash^scripttocapturesystemstatisticsOUTEILE=/home/
25、xu/capstats.csvDATE=,date+%m/%d/%Y’TIME二’date+%k:%m:%s,TIMEOUT:’uptime’VMOUT=,vmstat129USERS=,echo$TIMEOUT
26、gawk’{print$4厂’LOAD:’echoSTI.MEOUT
27、gawk{print$9}’
28、sed〃s/,//’’ERRE=,echo$VM0UT
29、sed-n’/[0~9]/p’
30、sed-n’2p’
31、gawk{print$4}IDLE=’echo$VMOUT
32、sed-n’/[0-9]/p’
33、sed-n’2p’
34、gawk{p
35、rint$15}’’echo〃.$DATE,.$TIME,WSERS,$LOAD,.$FREE,$IDLE"》$OUTFILE5、全方位监控主机井!/bin/bash#check_xu.sh#0****/homc/check_xu.shDAT="date+%Y%m%d"HOUR="date+%H"DIR="/home/oslog/host_${DAT}/${HOUR}"DELAY=60C0UNT=60#whethertheresponsibledirectoryexistif!test-d.${DIR}then/bin/mkdir-
36、p<${DIR}fi#generalcheckexportTERM=linux/usr/bin/top-b-d${DELAY}-n${COUNT}>${DIR}/top_$(DAT}.log2>&1cpucheck/usr/bin/sar-u${DELAY}${COUNT}>${DIR}/cpu_${DAT).log2>&1/usr/bin/mpstat-P0${DELAY}${COUNT}>${DIR}/cpu_0_${DAT}.log2>&1/usr/bin/mpstat-P1${DELAY}${COUNT}
37、>${DIR}/cpu—1—${DAT}.log2>&1memorych