The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 05-26-2009
mr_awd mr_awd is offline
Registered User
  
 

Join Date: May 2009
Posts: 2
Shell script to display top 5 process (per cpu consumption)

Hello,

I have to create shell script being myself real novice in scripting…
I was looking on the Internet for some script examples, but I don’t have the basic understanding of the shell. I was trying to do something with “ps” command without success.
For exemple total number of running process: ps ax | wc -l | tr -d ""
Executed from command line work nice, but once in the script like echo ‘ps ax | wc -l | tr -d ""’ return 1 which is not the right number of running process.

The script should do the following:

  • Should check the running processes
  • Display top five process (per cpu consumption)
  • output the summary for:
    • total number of processes
    • number of process per user
    • most common process
ex.: process1
process2
process3
process1
result : process1

Is it too difficult to implement in pure bash script?

Many thanks in advance for any help.