Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unix Shell script using AWK

Posted on 2007-11-15
4
Medium Priority
?
825 Views
Last Modified: 2012-06-27
$ ps vx | head -1 ; ps vx| egrep –v “idsldap | root” | grep –v PID |sort –rn +3 | head -10

PID TTY      STAT   TIME   MAJFL   TRS       DRS           RSS    % MEM       COMMAND
29403 ?       S        58:12      0         43           2362188   247084    0.7       db2agent (WPS1002) 0                
26440 ?      S        54:30     11        43          1939204    57404      0.1       db2agent (WPS1005) 0                
29417 ?       S        44:44      1         43           2721112   137272    0.4       db2agent (WPS1003) 0                
28698 ?       S        11:59      1         43           2348732   217272    0.6       db2agent (WPS1002) 0                
28228 ?       S          5:51      0         43           2349244   243492    0.7       db2agent (WPS1002) 0                
 4459 ?        S          4:48    111       43           2094192   162412    0.4       db2agent (WPS1004) 0                
 3180 ?       S          4:36      2         43           2720848    50964     0.1       db2agent (WPS1003) 0                
23302 ?      S          4:59      0         43           2721988    187180   0.5       db2agent (WPS1003) 0                
17972 ?       S          4:22      0         43           2720440    173944   0.5       db2agent (WPS1003) 0                
17970 ?        S          4:06      0         43           1939020    51924     0.1       db2agent (idle) 0                    


Hi Unix experts,

 I am looking for a unix shell script which  awks all databases(WPS1002,WPS1003,…..) and sum up the time  and RSS.

Database             Time(cpu)         RSS           %MEM
WPS1002    
WPS1003                  

Thanks,
Ahmed.
0
Comment
Question by:1981m
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 20294636
| awk '{rss[$11]+=$7;split($4,t,":");time[$11]+=y[0]*60+t[1]}END{for( n in rss ){ printf "%s\t%s\t%d:%02d\n",n,rss[n],time[n]/60, time[n]%60}}'
0
 

Author Comment

by:1981m
ID: 20302218
Hi ozo,

 This script is partially working, but it is not summing up the time.The time should be in HH:MM:Sec format.

Thanks.
0
 
LVL 84

Expert Comment

by:ozo
ID: 20303117
| awk '{rss[$11]+=$7;split($4,t,":");time[$11]+=t[1]*60+t[2]}END{for( n in rss ){ printf "%s\t%s\t%d:%02d\n",n,rss[n],time[n]/60, time[n]%60}}
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 20303141
There was only one : in the times in the example, if there are sometimes one : and sometimes two
awk '{rss[$11]+=$7;s=0;for(n=1;n<=split($4,t,":");n++){s*=60; s+=t[n]}time[$11]+=s}END{for( n in rss ){ printf "%s\t%s\t%d:%02d:%02d\n",n,rss[n],time[n]/60/60, time[n]/60%60,time[n]%60}}'
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question