#!/bin/bash
PS-E-O ' rsz,pid, ' | Sort-nrk1 | head-5 >/tmp/np.txt
PS-E-o ' pcpu,pid ' | Sort-nrk1 | head-5 >/tmp/up.txt
#查询内存使用情况
echo "========================================================================================================="
echo "==========================="
echo "Memory occupies the top five-bit app as:"
echo "==========================="
Echo-e ' \ n '
Cat/tmp/np.txt | While Read NLINE
Do
echo "app as:"
Ps-ef |grep ' echo $NLINE | awk ' {print $} ' | Grep-v "grep"
echo "takes up memory as (G):"
Npn1= ' echo $NLINE | awk ' {print '} '
npn2=1048576
awk ' begin{printf '%.2f\n ', ' $NPN 1 '/' $NPN 2 '} '
Echo-e ' \ n '
Done
echo "========================================================================================================="
#查询CPU使用率
Echo-e ' \ n '
echo "========================================================================================================="
echo "============================"
echo "CPU utilization top five apps are:"
echo "============================"
Cat/tmp/up.txt | While Read Uline
Do
echo "app as:"
Ps-ef |grep ' echo $ULINE | awk ' {print $} ' | Grep-v "grep"
echo "Cup usage is:"
echo $ULINE | awk ' {print '} '
Echo-e ' \ n '
Done
echo "========================================================================================================="
#查询内存和CPU使用率都较高的应用
Echo-e ' \ n '
echo "========================================================================================================="
echo "============================="
echo "Applications with high memory and CPU utilization:"
echo "============================="
Echo-e ' \ n '
Cat/tmp/np.txt | While Read Nuline
Do
If ["$ (Find/tmp/up.txt | Xargs grep ' echo $NULINE | awk ' {print $} ') '! = ' "];then
echo "app as:"
Ps-ef |grep ' echo $NULINE | awk ' {print $} ' | Grep-v "grep"
Echo-e ' \ n '
echo "takes up memory as (G):"
Npn1= ' echo $NULINE | awk ' {print '} '
npn2=1048576
awk ' begin{printf '%.2f\n ', ' $NPN 1 '/' $NPN 2 '} '
Echo-e ' \ n '
echo "Cup usage is:"
Find/tmp/up.txt| Xargs grep ' echo $NULINE | awk ' {print $} ' | awk ' {print '} '
Echo-e ' \ n '
Fi
Done
echo "========================================================================================================="
This article is from the "Operation and maintenance of the Road" blog, please be sure to keep this source http://lrtao2010.blog.51cto.com/10425744/1861450
Find memory, high CPU-intensive process scripts