您好,登錄后才能下訂單哦!
葉總給的腳本。
某應用系統在試運行期間,WEB端經常退出,為保證系統的應急響應,將WEB端部署成了5個節點,分別為zjgpwebnode1~5,并執行了監控進程:
一、創建監控執行腳本文件/home/monitor.sh,內容如下:
SHELL=/bin/bash
LANG=zh_CN.GB18030
SUPPORTED=zh_CN.GB18030:zh_CN:zh_CN.UTF-8:zh:en_US.UTF-8:en_US:en
LD_LIBRARY_PATH=/lib:/usr/lib:/lib64:/usr/lib64
export LANG
export SUPPORTED
export LD_LIBRARY_PATH
su - root >> /home/resetlog.log
LANG=zh_CN.GB18030
SUPPORTED=zh_CN.GB18030:zh_CN:zh_CN.UTF-8:zh:en_US.UTF-8:en_US:en
LD_LIBRARY_PATH=/lib:/usr/lib:/lib64:/usr/lib64
export LANG
export SUPPORTED
export LD_LIBRARY_PATH
WEBLOGIC1=`ps -ef|grep -c Dweblogic.Name=zjgpwebnode1`
WEBLOGIC2=`ps -ef|grep -c Dweblogic.Name=zjgpwebnode2`
WEBLOGIC3=`ps -ef|grep -c Dweblogic.Name=zjgpwebnode3`
WEBLOGIC4=`ps -ef|grep -c Dweblogic.Name=zjgpwebnode4`
WEBLOGIC5=`ps -ef|grep -c Dweblogic.Name=zjgpwebnode5`
WEBLOGIC6=`ps -ef|grep -c Dweblogic.Name=myserver`
if [ $WEBLOGIC1 != "2" ] ; then
date >> /home/resetlog.log
echo "Now Node1 is down!" >>/home/resetlog.log
locale >> /home/resetlog.log
set >> /home/resetlog.log
echo "Restart Node1 start" >>/home/resetlog.log
cd /home/weblogic/bea/user_projects/domains/webcluster/
nohup ./startManagedWebLogic.sh zjgpwebnode1 >1.out &
echo "Restart Node1 end" >>/home/resetlog.log
else
date >> /home/resetlog.log
echo "Node1 is OK!" >>/home/resetlog.log
fi
if [ $WEBLOGIC2 != "2" ] ; then
date >> /home/resetlog.log
echo "Now Node2 is down!" >>/home/resetlog.log
locale >> /home/resetlog.log
set >> /home/resetlog.log
echo "Restart Node2 start" >>/home/resetlog.log
cd /home/weblogic/bea/user_projects/domains/webcluster/
nohup ./startManagedWebLogic.sh zjgpwebnode2 >2.out &
echo "Restart Node2 end" >>/home/resetlog.log
else
date >> /home/resetlog.log
echo "Node2 is OK!" >>/home/resetlog.log
fi
if [ $WEBLOGIC3 != "2" ] ; then
date >> /home/resetlog.log
echo "Now Node3 is down!" >>/home/resetlog.log
locale >> /home/resetlog.log
set >> /home/resetlog.log
echo "Restart Node3 start" >>/home/resetlog.log
cd /home/weblogic/bea/user_projects/domains/webcluster/
nohup ./startManagedWebLogic.sh zjgpwebnode3 >3.out &
echo "Restart Node3 end" >>/home/resetlog.log
else
date >> /home/resetlog.log
echo "Node3 is OK!" >>/home/resetlog.log
fi
if [ $WEBLOGIC4 != "2" ] ; then
date >> /home/resetlog.log
echo "Now Node4 is down!" >>/home/resetlog.log
locale >> /home/resetlog.log
set >> /home/resetlog.log
echo "Restart Node4 start" >>/home/resetlog.log
cd /home/weblogic/bea/user_projects/domains/webcluster/
nohup ./startManagedWebLogic.sh zjgpwebnode4 >4.out &
echo "Restart Node4 end" >>/home/resetlog.log
else
date >> /home/resetlog.log
echo "Node4 is OK!" >>/home/resetlog.log
fi
if [ $WEBLOGIC5 != "2" ] ; then
date >> /home/resetlog.log
echo "Now Node5 is down!" >>/home/resetlog.log
locale >> /home/resetlog.log
echo "Restart Node5 start" >>/home/resetlog.log
cd /home/weblogic/bea/user_projects/domains/webcluster/
nohup ./startManagedWebLogic.sh zjgpwebnode5 >5.out &
echo "Restart Node5 end" >>/home/resetlog.log
else
date >> /home/resetlog.log
echo "Node5 is OK!" >>/home/resetlog.log
fi
if [ $WEBLOGIC6 != "2" ] ; then
date >> /home/resetlog.log
echo "Now TimerNode is down!" >>/home/resetlog.log
echo "Restart Timer Node start" >>/home/resetlog.log
cd /home/weblogic/bea/user_projects/domains/zjgpwebtimer
nohup ./startWebLogic.sh >> /home/logs/timer-web.log &
echo "Restart Timer Node end" >>/home/resetlog.log
else
date >> /home/resetlog.log
echo "Timer Node is OK!" >>/home/resetlog.log
fi
exit
請注意,該文件必須采用UltraEdit來編輯,并且保存時必須選擇為unix格式進行保存,主要是回車換行符的問題,否則匯報“syntax error: unexpected end of file”錯誤;
在實際執行時發現,采用crond系統計劃任務的方式進行運行時,環境變量與原來的root用戶登錄時不一致,導致系統有亂碼產生,故在腳本中增加了業務系統運行所需的環境變量;
二、創建好monitor.sh文件后,必須在計劃任務中添加該執行任務:
執行:crontab -e,添加
*/20 * * * * /home/monitor.sh
注:意思為每20分鐘執行一次監控程序monitor.sh
三、添加完成后重啟計劃任務程序以使計劃任務生效:
/sbin/service crond restart
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。