{"id":553,"date":"2011-01-28T00:30:38","date_gmt":"2011-12-23T05:51:50","guid":{"rendered":"http:\/\/kraftek.com\/blog\/parse-a-top-b-output-to-a-csv-file\/"},"modified":"2011-01-28T00:30:38","modified_gmt":"2011-12-23T05:51:50","slug":"parse-a-top-b-output-to-a-csv-file","status":"publish","type":"post","link":"\/blog\/index.php\/parse-a-top-b-output-to-a-csv-file\/","title":{"rendered":"Parse a top -b output to a csv file"},"content":{"rendered":"<p>To monitor a machine&#8217;s performance, in a very raw manner, you can run top in batch mode and redirect it to a file, like:<br \/>\n# top -b -c 10 &gt; topfile.txt &amp;<br \/>\nthen parse the output file\/s in a script<br \/>\n#!\/bin\/ksh<br \/>\necho &#8220;DATE,CPUIDLE,ME MUSED,MEMFREE&#8221;<br \/>\n(X=0;<br \/>\nB=&#8221;&#8221;;<br \/>\nawk &#8216;NF!=12 &amp;&amp; length&gt;0&#8217; top* | grep -iv defunct | while read line;do<br \/>\nL=`echo &#8220;$X % 5&#8221; | bc`<br \/>\nif [ $L -eq 0 ];then<br \/>\necho &#8220;$B&#8221;<br \/>\nB=&#8221;&#8221;<br \/>\nfi<br \/>\nB=`echo $B$line | sed &#8216;s\/ \/_\/g&#8217;`<br \/>\nX=`echo &#8220;$X + 1&#8221; | bc`<br \/>\ndone ) | awk -F&#8217;_&#8217; &#8216;{ print $3 &#8220;,&#8221; $31 &#8220;,&#8221; $41 &#8220;,&#8221; $43 }&#8217;<br \/>\nThis was tested on a linux Suse 9 on IBM OpenPower equipment.<br \/>\n=)<br \/>\nCreating a whole root zone<br \/>\nA whole root zone is a zone that has copies of packages in its own filesystem, not mounted as loopback.<br \/>\n# zonecfg -z wrzone<br \/>\nwrzone: No such zone configured<br \/>\nUse &#8216;create&#8217; to begin configuring a new zone.<br \/>\nzonecfg:wrzone&gt; create -b<br \/>\nzonecfg:wrzone&gt; set autoboot=true<br \/>\nzonecfg:wrzone&gt; set zonepath=\/wrzone<br \/>\nzonecfg:wrzone&gt; add net<br \/>\nzonecfg:wrzone:net&gt; set address=100.100.100.1<br \/>\nzonecfg:wrzone:net&gt; set physical=eri0<br \/>\nzonecfg:wrzone:net&gt; end<br \/>\nzonecfg:wrzone&gt; info<br \/>\nzonepath: \/wrzone<br \/>\nautoboot: true<br \/>\npool:<br \/>\nnet:<br \/>\n277\/433<br \/>\naddress: 100.100.100.1<br \/>\nphysical: eri0<br \/>\nzonecfg:wrzone&gt; verify<br \/>\nzonecfg:wrzone&gt; commit<br \/>\nzonecfg:wrzone&gt; exit<br \/>\n#<br \/>\n# cat \/etc\/zones\/wrzone.xml<br \/>\n&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br \/>\n&lt;!DOCTYPE zone PUBLIC &#8220;-\/\/Sun Microsystems Inc\/\/DTD Zones\/\/EN&#8221;<br \/>\n&#8220;file:\/\/\/usr\/share\/lib\/xml\/dtd\/zonecfg.dtd.1&#8243;&gt;<br \/>\n&lt;!&#8211;<br \/>\nDO NOT EDIT THIS FILE. Use zonecfg(1M) instead.<br \/>\n&#8211;&gt;<br \/>\n&lt;zone name=&#8221;wrzone&#8221; zonepath=&#8221;\/wrzone&#8221; autoboot=&#8221;true&#8221;&gt;<br \/>\n&lt;network address=&#8221;100.100.100.1&#8243; physical=&#8221;eri0&#8243;\/&gt;<br \/>\n&lt;\/zone&gt;<br \/>\n#<br \/>\n# chmod 700 \/wrzone<br \/>\n#<br \/>\n# df -h \/wrzone<br \/>\nFilesystem size used avail capacity Mounted on<br \/>\n\/dev\/dsk\/c0t1d0s0 7.8G 7.9M 7.7G 1% \/wrzone<br \/>\n#<br \/>\n# zoneadm -z wrzone verify<br \/>\n# zoneadm -z wrzone install<br \/>\nPreparing to install zone &lt;wrzone&gt;.<br \/>\nCreating list of files to copy from the global zone.<br \/>\nCopying &lt;118457&gt; files to the zone.<br \/>\n# zoneadm -z wrzone boot<br \/>\n# zlogin -C wrzone<br \/>\n278\/433<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To monitor a machine&#8217;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 &gt; topfile.txt &amp; then parse the output file\/s in a script #!\/bin\/ksh echo &#8220;DATE,CPUIDLE,ME MUSED,MEMFREE&#8221; (X=0; B=&#8221;&#8221;; awk &#8216;NF!=12 &amp;&amp; length&gt;0&#8217; top* | grep -iv defunct [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-553","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=553"}],"version-history":[{"count":0,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/553\/revisions"}],"wp:attachment":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=553"},{"taxonomy":"post_tag","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}