Parse a top -b output to a csv file

To monitor a machine’s performance, in a very raw manner, you can run top in batch mode and redirect it to a file, like:
# top -b -c 10 > topfile.txt &
then parse the output file/s in a script
#!/bin/ksh
echo “DATE,CPUIDLE,ME MUSED,MEMFREE”
(X=0;
B=””;
awk ‘NF!=12 && length>0’ top* | grep -iv defunct | while read line;do
L=`echo “$X % 5” | bc`
if [ $L -eq 0 ];then
echo “$B”
B=””
fi
B=`echo $B$line | sed ‘s/ /_/g’`
X=`echo “$X + 1” | bc`
done ) | awk -F’_’ ‘{ print $3 “,” $31 “,” $41 “,” $43 }’
This was tested on a linux Suse 9 on IBM OpenPower equipment.
=)
Creating a whole root zone
A whole root zone is a zone that has copies of packages in its own filesystem, not mounted as loopback.
# zonecfg -z wrzone
wrzone: No such zone configured
Use ‘create’ to begin configuring a new zone.
zonecfg:wrzone> create -b
zonecfg:wrzone> set autoboot=true
zonecfg:wrzone> set zonepath=/wrzone
zonecfg:wrzone> add net
zonecfg:wrzone:net> set address=100.100.100.1
zonecfg:wrzone:net> set physical=eri0
zonecfg:wrzone:net> end
zonecfg:wrzone> info
zonepath: /wrzone
autoboot: true
pool:
net:
277/433
address: 100.100.100.1
physical: eri0
zonecfg:wrzone> verify
zonecfg:wrzone> commit
zonecfg:wrzone> exit
#
# cat /etc/zones/wrzone.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE zone PUBLIC “-//Sun Microsystems Inc//DTD Zones//EN”
“file:///usr/share/lib/xml/dtd/zonecfg.dtd.1″>
<!–
DO NOT EDIT THIS FILE. Use zonecfg(1M) instead.
–>
<zone name=”wrzone” zonepath=”/wrzone” autoboot=”true”>
<network address=”100.100.100.1″ physical=”eri0″/>
</zone>
#
# chmod 700 /wrzone
#
# df -h /wrzone
Filesystem size used avail capacity Mounted on
/dev/dsk/c0t1d0s0 7.8G 7.9M 7.7G 1% /wrzone
#
# zoneadm -z wrzone verify
# zoneadm -z wrzone install
Preparing to install zone <wrzone>.
Creating list of files to copy from the global zone.
Copying <118457> files to the zone.
# zoneadm -z wrzone boot
# zlogin -C wrzone
278/433

Leave a Reply

Your email address will not be published. Required fields are marked *