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 proper format of out as it shown in the terminal.

[?25h[m[H[2J7[1;44r8System: ussbcap1[38CThu Jan 24 23:40:17 2013[BLoad averages: 4.50, 5.64, 6.52[B549 processes: 429 sleeping, 93 running, 27 zombies[BCpu states:[BCPU LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS[B 0 4.51 73.3% 0.0% 26.7% 0.0% 0.0% 0.0% 0.0% 0.0%[B 1 4.49 93.1% 0.0% 6.9% 0.0% 0.0% 0.0% 0.0% 0.0%[B--- ---- ----- ----- ----- ----- ----- ----- ----- -----[Bavg 4.50 83.2% 0.0% 16.8% 0.0% 0.0% 0.0% 0.0% 0.0%[2BMemory: 6586084K (6364224K) real, 8876320K (8507888K) virtual, 727260K free Page# 1/18[2BCPU TTY PID USERNAME PRI NI SIZE RES STATE TIME %WCPU %CPU COMMAND[B 1 ? 6922 mqm[6C234 24 15748K 2040K run 66562:13 40.53 40.46 autocons[B 1 ? 2372 root[5C152 20 15336K 1884K run 26462:41 25.87 25.83 dmisp[B 0 ? 5531 cyclone 152 20 206M 49916K run 76304:32 20.97 20.93 java[B 1 ? 26049 cyclone 152 20 1292M 1098M run 323:13 17.74 17.71 java[B 1 ? 20174 cyclone 152 20 1194M 1012M run[5C94:11 5.34 5.33 java[B 1 ? 3415 root[5C-16 20 45520K 8528K run 7149:30 2.12 2.12 midaemon[B 1 ? 8185 root[5C158 20 38164K 36416K sleep 0:00 4.36 1.29 sh[B 0 ? 8178 mqm[6C183 20 12900K 1388K run[6C0:00 3.70 1.22 auto_remote[B 0 ? 8192 mqm[6C183 20 12900K 1388K run[6C0:00 4.71 1.22 auto_remote[B 1 ? 37

PLEASE use code tags as demanded!
Reading man pages is highly educational and sometimes really helps. cf. man top :

The messy stuff in your sample is terminal control chars, usually introduced by an <ESC> char, followed by the terminal command (position, colour, ...). More info: man console_codes You can try to remove them with a script for awk, sed, perl, ...

Here is what i'm using on my HPUX boxes for basic CPU and DISK monitoring from cron in this manner :

00,5,10,15,20,25,30,35,40,45,50,55      *    *    *    *    /bin/awk -f /root/monitork /root/mon.data > /dev/null 2>&1

It's not perfect, but suits my needs :slight_smile:

BEGIN {
cpu=95
stat="1 100"
sms="mailx -s \"`hostname`\" smsaddress@domain.com"
ml="mailx -s \"`hostname` Overload\" mail.address@domain.com"
system("bdf > mon.data")
system("sar -u "stat" >> mon.data")
close("bdf >> mon.data")
close("sar -u "stat" >> mon.data")
}
match($0,/Average/) {
        if ( $2 > cpu ) {
        loadmon="SAR: CPU is above "cpu"% on "$2"% for "substr(stat,3,5) " seconds"
        }
}
match($0,/9[4-9]% \//) {
        diskmon="Mountpoints ALARM "$NF " is on "$(NF -1)
}
match($0,/100% \//) {
        print $NF $(NF -1)
        full="Mountpoints ALARM "$NF " is full"
}
END {
        if ( loadmon != "" ) {
                print loadmon | ml
                }
        if ( diskmon != "" || full != "" ) {
                print diskmon "\n" full | sms
                }
}

Hope that helps.