㈠ 求linux腳本,就是伺服器自動檢測網路,每個一段時間自動檢測,丟包嚴重或斷網,就自動重啟伺服器,求高手
因為伺服器自身網路丟包和斷網
1.數據交互過大
2.一段時間網口down掉
其實只要
/etc/init.d/network restart
並不需要重啟。
在/etc/rc.d/rc.local最下面加一句話
network.sh &
把下面腳本放到/usr/bin/目錄
並且給她加許可權
chmod +x /usr/bin/network.sh
network.sh腳本:
#!/bin/sh
#echo "請輸入你的網關地址"
#read sgateway
sgateway="192.168.3.187"
echo "連接的的網關是$sgateway"
delay=5000
echo "設置最大延遲不超過$delay毫秒"
nexttime=18
echo "每隔$nexttime秒進行一次檢查"
echo "########################################"
while :
do
network=`ping -c 1 $sgateway | awk 'NR==2 {print $7}' | sed "s/=/ /g" | awk '{print $2}'`
expr ${network} + 0 1>/dev/null 2>&1
if [ $? -eq 0 ]; then
/etc/init.d/network restart
else
value_n=`echo $network | sed "s/\.//g"`
if [ "$value_n" -lt "$delay" ];
then
echo "檢查結果為"
echo "網路通暢"
echo "網路延遲為$network秒"
echo "########################"
else
/etc/init.d/network restart
fi
fi
sleep $nexttime
done
不給分不給力啊
㈡ 關於linux腳本的,編寫腳本程序用於監測系統服務http的運行狀態請求高手幫忙啊...
把這個腳本命名為httpdemon.sh,放在home目錄下
#!/bin/sh
HOLD=/tmp/httpd0.$$
while [ 1 ]
do
ps -A | grep httpd | grep -v grep | awk '{print $2}' > $HOLD
if [ ! -s $HOLD ]; then
echo http service shutdown on `date` >> /var/log/htmon.log
fi
service httpd restart
ps -A | grep httpd | grep -v grep | awk '{print $2}' > $HOLD
if [ ! -s $HOLD ]; then
/bin/reboot
else
exit
fi
done
周一至周五每隔15分鍾執行一次監測就寫在crontab裡面
0,15,30,45 * * * 1-5 /home/httpdemon.sh
沒有具體測試過,如果不正確自己在調試下
㈢ 是用hostmonitor監控一台linux主機網路健康狀況,用的是一個ping的腳本,之前一直都是好的,今天突然在
只能有兩個可能:有關的文件系統滿了;或所用的directory文件夾沒有所需的寫的權利。
㈣ 如何實現linux效能監控腳本
本經驗咗嚛以centos為例演示,首先先安
1
伺服器能上網,通過yum之後找到 iotop
2
安裝好之後,我們可以通過rpm -qa
3
怎麼檢測centos進程負載直接輸入iotop
4
當然也可以通過輸入 iotop -o
5
至於iotop的使用方法還有很多命令,具
6
除了上述的磁碟讀寫的資源情況來
7
對於異常進程的查看,一般都是要確認有
㈤ 求助一個linux下shell腳本判斷無線網路狀況的問題,先行謝謝~
簡單講下思路吧,判斷是否斷網,一般可以通過ping網關。如果不通則執行重啟網路服務功能。
我簡單寫了個bash,不知道debian的是ksh還是csh,所以僅供參考。
--------------
#!/bin/sh
#假設1.254是網關
host=192.168.1.254
ping -c2 $host >>/dev/null
#我覺得你最大的疑問就是這里,怎麼判斷網路是否正常。你可以搜一下shell的變數。
if [ $? -eq 0 ];then
echo 「network is ok,exit...」
else
echo 「network is down,now restart network services」
#centos linux的網路服務重啟,根據你實際情況填寫
#/etc/init.d/network restart
fi
如有疑問可以留言。
㈥ linux網路狀態檢測腳本
呵呵!!!幫你解決下吧
實在不想看你的腳本,看得我頭暈,記得以後是熟悉shell scripts了回來看看現在的腳本體會下我的感受
cat /home/chk.sh
#!/bin/sh
if ! ping -c 5 192.168.2.252 > /dev/null 2>&1
then
echo "no ping" | mail -s "alarm" yourmailaddress
fi
*/5 * * * * root /home/chk.sh
㈦ 求教linux shell 後台網路監控腳本
#!/bin/bash
ping -c 3 www..com
YES=` echo $? `
if [ $YES -ne 0 ]
then
ok
fi
再設一個計劃任務就好了
OK 命令再好是絕對路經
㈧ 幾個常用的Linux監控腳本
幾個常用的Linux監控腳本
下面是幾個主機監控的腳本,大家可以根據自己的情況再進行修改,希望能給大家一點幫助。
1、查看主機網卡流量
#!/bin/bash
#network
#Mike.Xu
while : ; do
time='date +%m"-"%d" "%k":"%M'
day='date +%m"-"%d'
rx_before='ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7-'
tx_before='ifconfig eth0|sed -n "8"p|awk '{print $6}'|cut -c7-'
sleep 2
rx_after='ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7-'
tx_after='ifconfig eth0|sed -n "8"p|awk '{print $6}'|cut -c7-'
rx_result=$[(rx_after-rx_before)/256]
tx_result=$[(tx_after-tx_before)/256]
echo "$time Now_In_Speed: "$rx_result"kbps Now_OUt_Speed: "$tx_result"kbps"
sleep 2
done
2、系統狀況監控
#!/bin/sh
#systemstat.sh
#Mike.Xu
IP=192.168.1.227
top -n 2| grep "Cpu" >>./temp/cpu.txt
free -m | grep "Mem" >> ./temp/mem.txt
df -k | grep "sda1" >> ./temp/drive_sda1.txt
#df -k | grep sda2 >> ./temp/drive_sda2.txt
df -k | grep "/mnt/storage_0" >> ./temp/mnt_storage_0.txt
df -k | grep "/mnt/storage_pic" >> ./temp/mnt_storage_pic.txt
time=`date +%m"."%d" "%k":"%M`
connect=`netstat -na | grep "219.238.148.30:80" | wc -l`
echo "$time $connect" >> ./temp/connect_count.txt
3、監控主機的磁碟空間,當使用空間超過90%就通過發mail來發警告
#!/bin/bash
#monitor available disk space
SPACE='df | sed -n '/ \ / $ / p' | gawk '{print $5}' | sed 's/%//'
if [ $SPACE -ge 90 ]
then
[email protected]
fi
4、 監控CPU和內存的使用情況
#!/bin/bash
#script to capture system statistics
OUTFILE=/home/xu/capstats.csv
DATE='date +%m/%d/%Y'
TIME='date +%k:%m:%s'
TIMEOUT='uptime'
VMOUT='vmstat 1 2'
USERS='echo $TIMEOUT | gawk '{print $4}' '
LOAD='echo $TIMEOUT | gawk '{print $9}' | sed "s/,//' '
FREE='echo $VMOUT | sed -n '/[0-9]/p' | sed -n '2p' | gawk '{print $4} ' '
IDLE='echo $VMOUT | sed -n '/[0-9]/p' | sed -n '2p' |gawk '{print $15}' '
echo "$DATE,$TIME,$USERS,$LOAD,$FREE,$IDLE" >> $OUTFILE
5、全方位監控主機
#!/bin/bash
# check_xu.sh
# 0 * * * * /home/check_xu.sh
DAT="`date +%Y%m%d`"
HOUR="`date +%H`"
DIR="/home/oslog/host_${DAT}/${HOUR}"
DELAY=60
COUNT=60
# whether the responsible directory exist
if ! test -d ${DIR}
then
/bin/mkdir -p ${DIR}
fi
# general check
export TERM=linux
/usr/bin/top -b -d ${DELAY} -n ${COUNT} > ${DIR}/top_${DAT}.log 2>&1 &
# cpu check
/usr/bin/sar -u ${DELAY} ${COUNT} > ${DIR}/cpu_${DAT}.log 2>&1 &
#/usr/bin/mpstat -P 0 ${DELAY} ${COUNT} > ${DIR}/cpu_0_${DAT}.log 2>&1 &
#/usr/bin/mpstat -P 1 ${DELAY} ${COUNT} > ${DIR}/cpu_1_${DAT}.log 2>&1 &
# memory check
/usr/bin/vmstat ${DELAY} ${COUNT} > ${DIR}/vmstat_${DAT}.log 2>&1 &
# I/O check
/usr/bin/iostat ${DELAY} ${COUNT} > ${DIR}/iostat_${DAT}.log 2>&1 &
# network check
/usr/bin/sar -n DEV ${DELAY} ${COUNT} > ${DIR}/net_${DAT}.log 2>&1 &
#/usr/bin/sar -n EDEV ${DELAY} ${COUNT} > ${DIR}/net_edev_${DAT}.log 2>&1 &
放在crontab里每小時自動執行:
㈨ linux下幾個簡易的系統監控腳本
幾個常用的Linux監控腳本下面是幾個主機監控的腳本,大家可以根據自己的情況再進行修改,希望能給大家一點幫助。 1、查看主機網卡流量 #!/bin/bash #network #Mike.Xu while : ; do time='date +%m"-"%d" "%k":"%M' day='date +%m"-"%d' rx_bef...
㈩ 如何在linux系統下查看各種網路連接情況和網路連接狀態統計
寫一個shell腳本進行監控吧,這個不難做到哦, 看下wo 的網名行嗎?一定可以解決的啊!!