Bash wonkyness on Ubuntu versus RHEL

Posted by d34dh0r53 on Server Fault See other posts from Server Fault or by d34dh0r53
Published on 2010-03-26T19:50:47Z Indexed on 2010/03/26 19:53 UTC
Read the original article Hit count: 506

Filed under:
|
|
|

Fellow faulters,

I'm playing around with a one liner that I've developed on a RHEL 5.4 box and I have it working perfectly:

TOTAL_RAM=`free | grep Mem: | awk '{ print $2 }'`; \ 
ps axo rss,comm,pid | awk -v total_ram=$TOTAL_RAM \
'{ proc_list[$2] += $1; } END { for (proc in proc_list) \
{ proc_pct = (proc_list[proc]/total_ram)*100; 
printf("%d\t%s\t%0.2f%\n", proc_list[proc],proc,proc_pct); }}' \
| sort -n | tail -n 10

Which outputs something like the following on my RHEL box:

3736    logmon  0.01%
4156    EvMgrC  0.01%
4692    hald    0.01%
5020    ntpd    0.02%
6252    sshd    0.02%
7784    cvd     0.02%
9224    snmpd   0.03%
13068   dsm_sa_datamgr3 0.04%
23320   dsm_om_connsvc3 0.07%
4249864 mysqld  12.90%

However on my Ubuntu 9.04 slice I get this:

awk: run time error: not enough arguments passed to printf("%d  %s      %0.2f%
")
        FILENAME="-" FNR=104 NR=104
33248   console-kit-dae 3.17

I think it has to be bash that is borking something, but I'm really not doing anything that should be that bash specific. The RHEL box is running:

# yum info bash | grep -e Version -e Release
Version    : 3.2
Release    : 24.el5

And the Ubuntu box:

# apt-cache show bash | grep -e Version
Version: 3.2-5ubuntu1

I haven't dug into this super deeply, and thought I'd ping my fellow johnnys to see if you've ever run across this before.

/bow

© Server Fault or respective owner

Related posts about linux

Related posts about bash