Shell script code that counts CPU memory usage _linux shell

Source: Internet
Author: User
Tags memory usage
Copy Code code as follows:

#!/bin/sh
Clear
while ((1>0))
Todo
net=$ (NETSTAT-ANP | grep 1000 | grep EST | wc-l)
prc=$ (ps aux | grep thread1 | grep-v grep | grep-v Screen | awk ' {print ' CPU: "$"%, MEM: "$"%, RSS: "$6/1024" M, VSZ: "$5/1024" M, PID: "$" "}"
Tput SC; Echo-n-E "\b"; Tput RC;
echo "Srv:thread1, NET: $NET, $PRC"
echo ""
net=$ (NETSTAT-ANP | grep 1011 | grep EST | wc-l)
prc=$ (ps aux | grep thread2 | grep-v grep | grep-v Screen | awk ' {print ' CPU: "$"%, MEM: "$"%, RSS: "$6/1024" M , VSZ: "$5/1024" M, PID: "$" "}")
Tput SC; Echo-n-E "\b"; Tput RC;
echo "Srv:thread2, NET: $NET, $PRC"
echo ""
net=$ (NETSTAT-ANP | grep 1022 | grep EST | wc-l)
prc=$ (ps aux | grep thread3 | grep-v grep | grep-v Screen | awk ' {print ' CPU: "$"%, MEM: "$"%, RSS: "$6/1024" M , VSZ: "$5/1024" M, PID: "$" "}")
Tput SC; Echo-n-E "\b"; Tput RC;
echo "Srv:thread3, NET: $NET, $PRC"
echo ""
net=$ (NETSTAT-ANP | grep 1033 | grep EST | wc-l)
prc=$ (ps aux | grep thread4 | grep-v grep | grep-v Screen | awk ' {print ' CPU: "$"%, MEM: "$"%, RSS: "$6/1024" M , VSZ: "$5/1024" M, PID: "$" "}")
Tput SC; Echo-n-E "\b"; Tput RC;
echo "Srv:thread4, NET: $NET, $PRC"
echo ""
net=$ (NETSTAT-ANP | grep beam.smp | grep EST | grep 222.222.18.222:800 | wc-l)
prc=$ (ps aux | grep thread | grep-v grep | awk ' {CPU + = $} {MEM + $} {RSS = $} {VSZ = $} end {print CPU: "CPU" %, mem: "mem"%, RSS: "rss/1024" M, VSZ: "vsz/1024" M, "" ""} ' | awk ' End {print} ')
Tput SC; Echo-n-E "\b"; Tput RC;
echo "Srv:all, NET: $NET, $PRC"
echo ""
Sleep 0.5
Tput Cup 0 0
Done
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.