Code
1#!/bin/Bash2 #程序功能描述:3 # Monitoring System The amount of process memory occupied by the selected service4 #作者: Lone boat Point5#版本:1.06#创建时间: .-Ten- A Geneva: -: A7path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin8 Export PATH9#这里定义监控的服务名称或者PID号TenLine="NetworkManager" One AP= 'pwd` -file= $p/JiankongService.txt -Host= 'hostname` theDay= 'Date+"%y%m%d"` - - #判断文件夹是否存在, existing deletes the rebuild, does not exist the new - if[-D"$p/$i $host$day"]; Then + RM-rf"$p/$i $host$day" - mkdir "$p/$i $host$day" + Else A mkdir "$p/$i $host$day" at fi -CD $p/$i $host$day - -Pid= 'PS-ef |grep-Vgrep|grep "$line"|awk '{print $}'` - for((j=1; j<=144; j=j+1)) - Do in Touch$p/$i $host$day/$line. txt - if[!-f $p/$i $host$day/$line $pid.txt]; Then to Touch$p/$i $host$day/$line $pid.txt +Time= 'Date "+%y%m%d-%h%m%s"` -neicun= ' Top C-BN1 |grep-Vgrep|grep "$PID"|awk '{print $6}'` the Echo "$Time $NEICUN">> $p/$i $host$day/$line. txt * Echo "' cat $p/$i $host$day/$line. txt | grep-v grep | grep">> $p/$i $host$day/$line $pid.txt $ RM$p/$i $host$day/$line. txtPanax Notoginseng Sleep Ten - Else theTime= 'Date "+%y%m%d-%h%m%s"` +neicun= ' Top C-BN1 |grep-Vgrep|grep "$PID"|awk '{print $6}'` A Echo "$Time $NEICUN">> $p/$i $host$day/$line. txt the Echo "' cat $p/$i $host$day/$line. txt | grep-v grep | grep">> $p/$i $host$day/$line $pid.txt + RM$p/$i $host$day/$line. txt - Sleep Ten $ fi $ Done
Output format: Time Memory usage size
Monitor the process memory footprint of the services selected by the Linux system