Shell Script to grep output from top command.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script to grep output from top command.
# 1  
Old 03-14-2012
Shell Script to grep output from top command.

Hello,

I want a script which would grep details from top command for specific processes. I m not sure of the PID of these processes but i know the names.

Code:
[xmp@tswebpxmp8 ~]$ top -c
top - 16:41:55 up 160 days,  5:53,  2 users,  load average: 9.36, 9.18, 8.98
Tasks: 288 total,   9 running, 279 sleeping,   0 stopped,   0 zombie
Cpu(s): 34.0%us, 16.3%sy,  0.0%ni, 45.3%id,  0.3%wa,  0.2%hi,  3.9%si,  0.0%st
Mem:  49452208k total, 49154692k used,   297516k free,   539372k buffers
Swap: 16779884k total,      244k used, 16779640k free, 32430072k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5473 xmp       25   0 51224  34m 2864 R 99.7  0.1   1:53.26 logscan -in /var/xmp/logmgmt/work_billing/pending/XMP_tswebpxmp8_1203140830.log -out XMP_tswebpxmp8_1203140
23199 xmp       15   0 1135m 1.1g 5660 R 81.4  2.2   5398:45 cee -n TCP-ROUTER.tswebpxmp8.4
28549 xmp       16   0 1264m 1.2g 5660 R 73.8  2.5   7514:20 cee -n TCP-ROUTER.tswebpxmp8.11
32675 xmp       16   0 1274m 1.2g 5660 R 72.1  2.5   7297:01 cee -n TCP-ROUTER.tswebpxmp8.12
23148 xmp       15   0 1147m 1.1g 5660 S 71.8  2.3   5698:58 cee -n TCP-ROUTER.tswebpxmp8.2
26869 xmp       16   0 1147m 1.1g 5660 R 66.2  2.3   5644:15 cee -n TCP-ROUTER.tswebpxmp8.8
24956 xmp       15   0 1142m 1.1g 5660 R 59.2  2.2   5706:29 cee -n TCP-ROUTER.tswebpxmp8.6
21247 xmp       15   0 1205m 1.1g 5672 S 58.5  2.4   5316:25 cee -n TCP-ROUTER.tswebpxmp8.1
26862 xmp       15   0 1130m 1.0g 5660 S 57.5  2.2   5451:44 cee -n TCP-ROUTER.tswebpxmp8.7
23155 xmp       15   0 1117m 1.0g 5660 S 48.2  2.2   5261:25 cee -n TCP-ROUTER.tswebpxmp8.3
26870 xmp       15   0 1119m 1.0g 5660 S 47.9  2.2   5542:04 cee -n TCP-ROUTER.tswebpxmp8.9
24955 xmp       16   0 1163m 1.1g 5660 S 46.9  2.3   5607:23 cee -n TCP-ROUTER.tswebpxmp8.5
28546 xmp       15   0 1132m 1.0g 5660 R 46.9  2.2   5472:32 cee -n TCP-ROUTER.tswebpxmp8.10

I want to grep details of every TCP-ROUTER process. how do i do it.

-Siddhesh
# 2  
Old 03-14-2012
Code:
 
top -b -n 1 | grep "TCP-ROUTER"

# 3  
Old 03-14-2012
I tried this, it does not work

Code:
[xmp@tswebpxmp7 ~]$ top -b -n 1 | grep "TCP-ROUTER"
[xmp@tswebpxmp7 ~]$ top -b -n 1 | grep "TCP-ROUTER*"
[xmp@tswebpxmp7 ~]$ top -b -n 1 | grep TCP-ROUTER
[xmp@tswebpxmp7 ~]$ top -b -n 1 | grep TCP-ROUTER*

-Siddhesh
# 4  
Old 03-14-2012
Is the below top command shows the "TCP-ROUTER" ?

Code:
 
top -b -n 1

if you want to grep the process details, the use

Code:
 
ps -ef | grep "TCP\-ROUTER"

# 5  
Old 03-14-2012
I want to get the process details of these. like memory utilization/CUP utilization which we get in top command.

-Siddhesh
# 6  
Old 03-14-2012
Is the below top command shows the "TCP-ROUTER" ?



Code:
 top -b -n 1

# 7  
Old 03-14-2012
provide the -c flag as well, you need the full command line for TCP-ROUTER to appear in the output, thus
Code:
top -bcn 1 | grep "TCP-ROUTER"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Top Command Output is not coming via Cronjob

Dear All, I created a small script to get the CPU, GIS usage etc automatically. However when i run this script manually its working , but when i run through cronjob i am not getting any output. Can anyone please help me on this. I am using SuseLinux. Thank you in advance. #!/bin/sh {... (2 Replies)
Discussion started by: Nitin Kapoor
2 Replies

2. UNIX for Dummies Questions & Answers

Unable to scroll to the top of the output of a command

Hello, I am a beginner, I have currently Solaris 11 on a vmware machine. Whenever I type a command like 'ls' the screen scrolls to the end of the screen. I am unable to see the entire list of directories and files. I have tried ls |page command, but looking out for a better option. (3 Replies)
Discussion started by: farheenprasad
3 Replies

3. Shell Programming and Scripting

Format Top and prstat command output

need help with formatting output of command top and prstat. My requirment is to remove few columns and display remaining . But when i used awk to do that the output seems to be have gone vague, mixing the column values. After using awk to print particular column the output seems to have lost... (1 Reply)
Discussion started by: NarayanaPrakash
1 Replies

4. HP-UX

Formatted TOP command output in file

Hi All, I want generate HP-UX overall system performance report. I tried executing top command and write that out put to file. but am not able to view the report in proper format. I can see report like below in file but i can see properly in terminal. Please suggest how can i get... (2 Replies)
Discussion started by: lravip123
2 Replies

5. UNIX for Advanced & Expert Users

Conflicts in the output of TOP command

Hi All, In the output of TOP command in my unix system, i monitored that some process has utilization more than 100% even some process has 4000% utilisation. Please help me understand how it is possible to show more than 100% utilization. Please see the screenshot below:... (2 Replies)
Discussion started by: anand2308
2 Replies

6. Shell Programming and Scripting

Need help with shell script - output of top command

I have written shell script to send file as an attachemt of email and output of "top -o res" command as email body. it works fine if i execute manually from prompt but it does not send "top -o res" command output in email body when it is executed via crontab. Any suggestions. My script is below:... (5 Replies)
Discussion started by: needyourhelp10
5 Replies

7. Shell Programming and Scripting

Extract header from top command output

hi, I want to extract and save the cpu(s) information from top command output, but individual cpu statistics separately on a multi-processor machine. In command line, top will show this statistics when we press the switch "1". any ideas? thanks, meharo (3 Replies)
Discussion started by: meharo
3 Replies

8. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

9. Shell Programming and Scripting

how to redirect the output of a grep command to a file inside a shell script

hi, i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (11 Replies)
Discussion started by: kripssmart
11 Replies

10. UNIX for Dummies Questions & Answers

how to get the output of a grep command to a file inside a shell script

hi, i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (1 Reply)
Discussion started by: kripssmart
1 Replies
Login or Register to Ask a Question