nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

list path for apache process with great cpu usage

This is a discussion on list path for apache process with great cpu usage within the Shell scripting forums, part of the Development/Scripting category; Hy, I tryed this for a in `ps -eo pid,pcpu,comm | sort -n -k2 | grep 'httpd'|tail -10|awk '{print $1}'`; ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 16-08-2008, 09:33 PM
Junior Member
User
 
Join Date: Jul 2008
Location: SM
OS: CentOs
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cosminnci is on a distinguished road
Default list path for apache process with great cpu usage

Hy,


I tryed this
for a in `ps -eo pid,pcpu,comm | sort -n -k2 | grep 'httpd'|tail -10|awk '{print $1}'`; do pwdx $a; done

works but I want to also insert the cpu % in front something like:

for a in `ps -eo pid,pcpu,comm | sort -n -k2 | grep 'httpd'|tail -10|awk '{print $2 " " $1}'`; do pwdx $a; done

but $a takes both values.
how can this be donne?

Thanks,
Cosmin
Reply With Quote
  #2 (permalink)  
Old 17-08-2008, 03:18 AM
rockdalinux's Avatar
Is that all you got?
User
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 703
Thanks: 15
Thanked 19 Times in 18 Posts
Rep Power: 10
rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light
Default

You need to try as follows:
Code:
#!/bin/bash
ps -eo pid,pcpu,comm | sort -n -k2 | grep 'httpd'|tail -10 | awk '{ print $1 " " $2}' > /tmp/output
while read line; 
do 
 a=$(echo $line | awk '{ print $1 }'); 
 b=$(echo $line | awk '{ print $2 }'); 
 echo "$(pwdx $a) (${b}%)"; 
done < /tmp/output
/bin/rm /tmp/output
__________________
Rocky Jr.
What's wrong? I hope I am not making you uncomfortable...

Never send a boy to do a mans job.
Reply With Quote
  #3 (permalink)  
Old 18-08-2008, 01:47 AM
Junior Member
User
 
Join Date: Jul 2008
Location: SM
OS: CentOs
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cosminnci is on a distinguished road
Default

Thanks for the solution, this would work in an script but I would prefer to run it as a single line command, I need to run it on several servers.
Reply With Quote
  #4 (permalink)  
Old 18-08-2008, 03:38 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,706
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Quote:
Originally Posted by cosminnci View Post
Thanks for the solution, this would work in an script but I would prefer to run it as a single line command, I need to run it on several servers.
call pwdx from awk itself:
Code:
 ps -eo pid,pcpu,comm | sort -n -k2 | grep 'httpd'|tail -10|awk '{ORS="% "; system("pwdx " $1); print $2}'
Read awk man page to get more info about ORS variable.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 19-08-2008, 02:21 AM
Junior Member
User
 
Join Date: Jul 2008
Location: SM
OS: CentOs
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cosminnci is on a distinguished road
Default

Yep, works great, thank you.
ORS The output record separator, by default a new­ line.Thanks,
Reply With Quote
Reply

Tags
awk , bash , pipes , ps command , pwdx


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
How can I set Path in bash shell chanderbio Shell scripting 2 13-06-2008 10:38 AM
Change /tmp path on KDE as it is too small for KDE marccarter0 Ubuntu / Debian 2 26-05-2008 09:34 PM
CPU usage Shell script (Monitoring CPU Usage) atulmatkar Shell scripting 2 10-05-2008 10:24 PM
Killing of a process and send a mail if the process doesnot come up within 2 minutes Prince89 Shell scripting 1 11-02-2008 12:39 PM
vivek: thanks for a great site fragbait The Hangout 3 14-12-2006 05:13 PM


All times are GMT +5.5. The time now is 11:51 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38