1822034 Members
3317 Online
109639 Solutions
New Discussion юеВ

Need help with script

 
SOLVED
Go to solution
Hunki
Super Advisor

Need help with script

Hi Everyone,

I have to make a script in which I have take a word count of 39 processes.which is the easiest way to take the work count with the help of unix script.

Thanks,

Hunki
6 REPLIES 6
TKeller
Frequent Advisor

Re: Need help with script

ps -ef | grep -v grep | grep | wc -l

or

ps -ef | grep -v grep | grep | wc -c

---

What are you looking to do so I can refine that basic one-liner?
It is said you should treat your body like a temple. I treat mine like an amusement park.
Rick Garland
Honored Contributor

Re: Need help with script

The command is 'wc -w'

Execute the command to list process and pipe that to wc -w

Example
ps -ef | wc -w

This will list all of the processes and provide count of the number of words.

Hunki
Super Advisor

Re: Need help with script

I have a list of 39 processes which are existent on the system with the same name in multiple counts. What I mean is that each of the 39 processes have multiple processes by the same name.Like processes X Y Z, then X may be present 5 times.So I need to do a word count on each one of them, is it possible to put them in a file as a list and then get their word with the help of xargs.
spex
Honored Contributor

Re: Need help with script

ps -e |awk '{print $4}' |uniq -c |sort
Doug O'Leary
Honored Contributor
Solution

Re: Need help with script



for p in $(cat list-o-procs)
do
num=$(ps -ef | grep ${p} | grep -v grep | wc -l)
printf "%s %d\n" ${p} ${num}
done


------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Hunki
Super Advisor

Re: Need help with script

Thanks Doug!