| ||||
| | ||||
| | الصفحة الرئيسية :: الشركات الرسمية :: شركات الإستضافة :: شركات التصميم :: الشركات الاعلانية :: شركات الدعم الفني :: شروط إضافة موقع | |||
| | رقم المشاركة : 1 (permalink) | ||
|
|
بسم الله الرحمن الرحيم كود: */15 * * * * sh /home/sysadm/script/load.sh /home/sysadm/script - مكان السكربت او مساره /home/sysadm/script/tmp/ - الملفات المؤقته يفضل عدم وضع السكربت في مسار آخر 3 - هنا يمكنك تحديد استلام رسالة او لا اذا تم حل المشكله : كود: # echo "no" > /home/sysadm/script/tmp/loadreply 4 - قم بتغير البريد [فقط الأعضاء المسجلين والمفعلين يمكنهم رؤية الوصلات . إضغط هنا للتسجيل] الى اميلك في السكربت السكربت : كود: #!/bin/bash
infofile="/home/sysadm/www/loadinfo.`date +%d-%m-%Y`.txt" # File will store the all status to diagnose the load problem
temp="/home/sysadm/script/tmp/mailinfo" # File will store the formated output when load is high
loadreply="/home/sysadm/script/tmp/loadreply" # File will store formated output when load avg problem is solved
srvrnm=`hostname` # get the hostname of the server [/color]
cur=`uptime | awk '{print $10}' | tr -d , | cut -d. -f1` # Get the current load of the server
if [ $cur -ge 3 ]; then # Condition if the server load is greater then 3 then sent Alert email, you can change this value
#################### Formating Server Statistics to diagnose the server when server load is high ##################
echo " " >> $infofile
echo " " >> $infofile
echo " " >> $infofile
echo "_____________________________________________________________________________________________________" >> $infofile
echo "High Load Average `date`, please find detailed information of it as mentioned below:" >> $infofile
echo "_____________________________________________________________________________________________________" >> $infofile
echo " " >> $infofile
echo " " >> $infofile
echo "------------------" >> $infofile
echo "| Uptime status: |" >> $infofile
echo "------------------" >> $infofile
/usr/bin/uptime >> $infofile ##### Adding uptime status
echo " " >> $infofile
echo "-----------------------------------" >> $infofile
echo "| Top 20 CPU consuming processes: |" >> $infofile
echo "-----------------------------------" >> $infofile
ps aux | head -1 >> $infofile
#ps aux | sort -rn +2 | head -20 >> $infofile
ps aux --no-headers | sort -rn +2 | head -20 >> $infofile #### Top 20 cpu consuming process
echo " " >> $infofile
echo "-----------------------------------" >> $infofile
echo "| Top 10 memory-consuming processes: |" >> $infofile
echo "-----------------------------------" >> $infofile
ps aux | head -1 >> $infofile
ps aux --no-headers| sort -rn +3 | head >> $infofile #### Top 10 memory consuming process
echo " " >> $infofile
echo "---------------------------" >> $infofile
echo "| Memory and Swap status: |" >> $infofile
echo "---------------------------" >> $infofile
/usr/bin/free -m >> $infofile ###### Memory usage status
echo " " >> $infofile
echo "------------------------------" >> $infofile
echo "| Active network connection: |" >> $infofile
echo "------------------------------" >> $infofile
/bin/netstat -tnup | grep ESTA >> $infofile # All active network connectins
echo " " >> $infofile
echo "---------------------------" >> $infofile
echo "| Disk Space information: |" >> $infofile
echo "---------------------------" >> $infofile
/bin/df -h >> $infofile # get the disk status information also
echo " " >> $infofile
echo "______________________________________________________________________________________________" >> $infofile
echo " " >> $infofile
###################################################################
################### Formation for email output ##########################
echo "Hi," > $temp
echo " " >> $temp
echo " " >> $temp
echo "Presently we have noticed high server load on `hostname`." >> $temp
echo " " >> $temp
echo "Please find the status of `hostname` server using below mentioend URL: http://$srvrnm/sysadm/loadinfo.`date +%d-%m-%Y`.txt" >> $temp
echo " " >> $temp
echo " " >> $temp
echo "Thanks," >> $temp
echo " " >> $temp
echo "- Linux SysAdmin." >> $temp
######################################################
mail -s "Alert: Server Load `hostname`" abc@yourdom.com < $temp
echo "yes" > $loadreply ## Change value in loadreply file to sent email when problem is resolved
fi
#### Condition to sent email when load problem is resolved by sysadmin ######
if [ `cat $loadreply` = 'yes' ] && [ $cur -le 1 ]; then
################### Formation for email output ##########################
echo " " > $temp
echo "Hi," >> $temp
echo " " >> $temp
echo "The server had high utilization problem and it is recovered from that" >> $temp
echo "Current load of the server is:" >> $temp
echo " " >> $temp
echo " " >> $temp
echo "`uptime`" >> $temp
echo " " >> $temp
echo "Thanks," >> $temp
echo " " >> $temp
echo "- Linux Sysadmin." >> $temp
######################################################
mail -s "Alert: Server Load is under control for `hostname` on `date`" abc@yourdom.com < $temp
echo "no" > $loadreply # change the value in laod reply file that problem is solved
fi
############## End of Script ######### شبكة الدعم العربي المهندس ياسر 0506682558
| ||
|
| |
![]() |
| أدوات الموضوع | |
| طرق مشاهدة الموضوع | |
|
|
| |
| اشتراك في "مجموعة العالم التقني العربي" Arab Technical World |
| زيارة هذه المجموعة |
| جميع الحقوق محفوظة لمنتديات شبكة آرا ويب لخدمات الانترنت © 2007 | |