1、Readme:html
#!/bin/sh df_max=`cat para.txt | grep 'df_max'|awk -F ":" '{print$2}'` #dev/root百分值的上限,具體數值在同路徑下的 para.txt中獲取 df > df.txt root=$(cat df.txt | awk 'NR==2{print}'| awk '{print $5}' | awk -F "%" '{print$1}') # awk 'NR==2{print}'| awk '{print $5}':第2行第5列 if [ $root -lt $df_max ] # [] 跟條件語句之間要加 !!空格!! ;若是當前dev/root百分值大於上限,打印error then echo `date`" : dev/root OK" else echo `date`" : dev/root false" fi
#!/bin/sh asterisk_vsz_max=`cat para.txt | grep 'asterisk_vsz_max'|awk -F ":" '{print$2}'` asterisk_vsz_min=`cat para.txt | grep 'asterisk_vsz_min'|awk -F ":" '{print$2}'` top -b n1 > top.txt vsz=$(cat top.txt |grep 'asterisk -vvv'| awk '{print $5}' | awk -F "m" '{print$1}') #echo $vsz if [[ $vsz -gt $asterisk_vsz_min ]] && [[ $vsz -lt $asterisk_vsz_max ]] # 小細節:if 多條件判斷語句,要兩個[] ;參數與[]之間要有空格 then echo `date`" : asterisk vsz :"$vsz", OK" else echo `date`" : asterisk vsz :"$vsz", false" fi
#!/bin/sh #set -xv echo "" > cpu.txt cpu_max=` cat para.txt | grep 'cpu_max'|awk -F ":" '{print$2}'` #cpu的上限 ,具體數值在同路徑下的 para.txt中獲取 time=0 times=$cpu_checktime #要測試的cpu次數,一秒測試一次打印一次cpu值 errortimes=$cpu_allowerrortime #容許超過指定cpu上限的次數 for i in $(seq 1 $times) do echo "`cpu -c 1`" >> cpu.txt cpu=$(tac cpu.txt | awk "NR==1" | awk '{print $3}' | awk -F "%" '{print$1}') # echo "cpu:"$cpu if [ $cpu -gt $cpu_max ] #若是cpu > 指定值maxcpu,次數+1 then time=$(($time+1)) echo "time:"$time else time=$time fi done if [ $time -gt $errortimes ] #若是指定次數maxtime內,cpu超過maxcpu次數大於指定值次數errortime;打印error then echo `date`" : cpu false" else echo `date`" : cpu OK" fi
#!/bin/sh #set -xv free_min=`cat para.txt | grep 'free_min'|awk -F ":" '{print$2}'` #內存的下限 cach_max=`cat para.txt | grep 'cach_max'|awk -F ":" '{print$2}'` #cached的上限 #free_min=47084 #cach_max=324000 if [ ! -f "memory.txt" ] #判斷memory.txt是否存在---第一次運行該腳本不存在,若不存在則執行then部分 then cat /proc/meminfo > memory.txt cp memory.txt memory1.txt cp memory.txt memory2.txt cp memory.txt memory3.txt cp memory.txt memory4.txt cp memory.txt memory5.txt else break; fi a=0 b=0 memfree=`cat memory.txt | awk 'NR==2{print}' | awk '{print$2}'` cached=`cat memory.txt | awk 'NR==4{print}' | awk '{print$2}'` if [[ $memfree -ge $free_min ]] && [[ $cached -lt $cach_max ]] #判斷當前的free跟cach是否超過限制範圍,若沒超過則執行then部分進一步判斷 then mv memory4.txt memory5.txt mv memory3.txt memory4.txt mv memory2.txt memory3.txt mv memory1.txt memory2.txt mv memory.txt memory1.txt cat /proc/meminfo > memory.txt for i in $(seq 1 5) #當前的free跟cach與memory1.txt到memory5.txt對比 do memfreelast=`cat memory$i.txt | awk 'NR==2{print}' | awk '{print$2}'` #echo $memfreelast cachedlast=`cat memory$i.txt | awk 'NR==4{print}' | awk '{print$2}'` #echo $cachedlast if [ $memfree -ge $memfreelast ] then if [ $cached -le $cachedlast ] then echo `date`" : memory and cached OK" break else b=$(($b+1)) fi else a=$(($a+1)) fi i=$((i+1)) done if [ $a -eq 5 ];then echo `date`" : memfree continue leak:false" fi if [ $b -eq 5 ];then echo `date`" : cached continue leak:false" fi else echo `date`"memory overflow,please chech memfree and cached : false " fi
#!/bin/sh #top.txt sed -n '1,20p' top.txt > topsed1.txt #把top.txt的前1-20行另存爲 topsed1.txt(太多行會破壞格式,因此保留的20行) sed 's/,/;/g ' topsed1.txt > topsed2.txt #把topsed1.txt中的 「,」都換成「;」另存到 topsed2.txt中 (由於csv是把「,」當成換單元格,因此把內容中的「,」替換掉以保持格式便於查看) sleep 1 sed '1i"' topsed2.txt > topsed3.txt #在topsed2.txt的第一行插入符號" sleep 1 sed '$a"' topsed3.txt > topsed4.txt #在topsed3.txt的最後一行插入符號 " sed 'H;$!d;${x;s/^\n//;s/\n/\r\n/g}' topsed4.txt > top_final.txt # 在topsed4.txt 把換行符由原來的「\n」改爲「\r\n」(excel的換行符是\r\n,這樣在window打開能夠保持top.txt輸出的換行效果) #若是有其餘txt內容須要改造,按照top.txt這個模式copy改造便可,以下 #df.txt sed 's/,/;/g ' df.txt > dfsed1.txt sleep 1 sed '1i"' dfsed1.txt > dfsed2.txt sleep 1 sed '$a"' dfsed2.txt > dfsed3.txt sed 'H;$!d;${x;s/^\n//;s/\n/\r\n/g}' dfsed3.txt > df_final.txt #cpu.txt sed 's/,/;/g ' cpu.txt > cpu1.txt sleep 1 sed '1i"' cpu1.txt > cpu2.txt sleep 1 sed '$a"' cpu2.txt > cpu3.txt sed 'H;$!d;${x;s/^\n//;s/\n/\r\n/g}' cpu3.txt > cpu_final.txt #memory.txt sed 's/,/;/g ' memory.txt > memory1.txt sleep 1 sed '1i"' memory1.txt > memory2.txt sleep 1 sed '$a"' memory2.txt > memory3.txt sed 'H;$!d;${x;s/^\n//;s/\n/\r\n/g}' memory3.txt > memory_final.txt echo "`date`"",""`cat df_final.txt`"",""`cat top_final.txt`"",""`cat calls_final.txt`"",""`cat memory_final.txt`">> stabilitycsv$PBX_IP.csv #若是要新加入單元格內容,在此添加,記得","換單元格
#!/usr/bin/expect set PBX_IP [lindex $argv 0] ;#取自命名後帶的第一個參數值,設置爲鏈接的ip,參數值之間以空格隔開; [lindex $argv 0]表示執行命令行帶的第一個參數值 set password [lindex $argv 1] ;#取自命令後待的第二個參數值,設置爲鏈接的密碼;無該參數值表示密碼爲空 spawn ftp $PBX_IP expect "Name" send "root\r" expect "Password:" send "$password\r" expect "ftp>" send "bin\r" expect "ftp>" send "get df.txt\r" expect "ftp>" send "get cpu.txt\r" expect "ftp>" send "bye\r"