使用shell脚本进行服务器系统监控——进程监控实例

使用shell脚本进行服务器系统监控——进程监控实例

ID:10269647

大小:65.50 KB

页数:12页

时间:2018-06-14

使用shell脚本进行服务器系统监控——进程监控实例_第1页
使用shell脚本进行服务器系统监控——进程监控实例_第2页
使用shell脚本进行服务器系统监控——进程监控实例_第3页
使用shell脚本进行服务器系统监控——进程监控实例_第4页
使用shell脚本进行服务器系统监控——进程监控实例_第5页
资源描述:

《使用shell脚本进行服务器系统监控——进程监控实例》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、使用shell脚本进行服务器系统监控——进程监控#!/bin/kshtypeset-uRUN_PRE_EVENT#ForcetoUPPERCASEtypeset-uRUN_STARTUP_EVENT#ForcetoUPPERCASEtypeset-uRUN_POST_EVENT#forcetoUPPERCASERUN_PRE_EVENT='N'#A'Y'willexecute,anythingelsewillnotRUN_STARTUP_EVENT='Y'#A'Y'willexecute,anythingelsewillnotRUN_POST_EVENT='Y'#A

2、'Y'willexecute,anythingelsewillnotLOGFILE="/tmp/proc_status.log"[[!-s$LOGFILE]]&&touch$LOGFILESCRIPT_NAME=$(basename$0)TTY=$(tty)INTERVAL="1"#SecondsbetweensamplingJOBS=#################################################################DEFINEFUNCTIONSHERE#################################

3、###################################usage(){echo"tUSAGEERROR"echo"USAGE:$SCRIPT_NAMEsecondsprocess"echo"Willmonitorthespecifiedprocessforthe"echo"specifiednumberofseconds."echo"USAGE:$SCRIPT_NAME[-s-Sseconds][-m-Mminutes]"echo"[-h-Hhours][-d-Ddays][-p-Pprocess]"echo"Wil

4、lmonitorthespecifiedprocessfornumberof"echo"secondsspecifiedwithin-sseconds,-mminutes,"echo"-hhoursand-ddays.Anycombinationofcommand"echo"switchescanbeused."echo"EXAMPLE:$SCRIPT_NAME300dtcalc"echo"EXAMPLE:$SCRIPT_NAME-m5-pdtcalc"echo"Bothexampleswillmonitorthedtcalcprocess"ec

5、ho"for5minutes.Canspecifydays,hours,minutes"echo"andseconds,using-d,-h,-mand-s"}####################################################trap_exit(){#set-x#Uncommanttodebugthisfunction#Loganendingtimeforprocessmonitoringecho"INTERRUPT:ProgramReceivedanInterrupt...EXITING...">$TTYecho"IN

6、TERRUPT:ProgramReceivedanInterrupt...EXITING...">>$LOGFILETIMESTAMP=$(date+%D@%T)#Getanewtimestamp...echo"MON_STOPPED:Monitoringfor$PROCESSended==>$TIMESTAMP">>$TTYecho"MON_STOPPED:Monitoringfor$PROCESSended==>$TIMESTAMP">>$LOGFILEecho"LOGFILE:AllEventsareLogged==>$LOGFILE">$TT

7、Y#KillallfunctionsJOBS=$(jobs-p)if[[!-z$JOBS&&$JOBS!=''&&$JOBS!='0']]thenkill$(jobs-p)2>/dev/null1>&2fireturn2}####################################################pre_event_script(){#PutanythingthatyouwanttoexecuteBEFOREthe#monitoredprocessSTARTSinthisfunction:#No-OP-Neededasaplaceho

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。