<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Script for top. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-top/m-p/2764042#M73134</link>
    <description>Let's look at the whole thing, and break it down into pieces. The whole thing:&lt;BR /&gt;&lt;BR /&gt;awk '{if(($1~/CPU/)&amp;amp;&amp;amp;($2~/TTY/)){getline; printf("%6s %3.0f %9s %s\n",$3,$11,$4,$NF);getline; printf("%6s %3.0f %9s %s\n",$3,$11,$4,$NF)}}' /tmp/xxx &amp;gt;/tmp/yyy&lt;BR /&gt;&lt;BR /&gt;Note that I added one other } before the last ' to close the if statement.&lt;BR /&gt;&lt;BR /&gt;The general form is:&lt;BR /&gt;awk 'pattern{commands}' inputfile &amp;gt; outputfile&lt;BR /&gt;&lt;BR /&gt;So awk is getting its input from /tmp/xxx, and putting its output into /tmp/yyy.&lt;BR /&gt;&lt;BR /&gt;In this awk script, we do not have any of the (optional) patterns. (If patterns were present, then awk would execute to commands if and only if the pattern was matched. I'm sure that we could change this script to use patterns if needed.)&lt;BR /&gt;&lt;BR /&gt;With no patterns, we will execute the commands for every line of input.&lt;BR /&gt;&lt;BR /&gt;The only command is an if statement. If the first parameter of the input line ($1) is "CPU" and the second parameter ($2) is "TTY", then the commands inside the second set of {} will be executed.&lt;BR /&gt;&lt;BR /&gt;getline throws out the current line of data, and gets the next line from the input file. That will be the line containing data for the first process. printf just formats the output. In this case, we are printing out four values: the third ($3), eleventh ($11), fourth (4$), and total number of fields on the line ($NF).&lt;BR /&gt;&lt;BR /&gt;To get the data for the second process, we just repeat the getline (which puts new values in $1, $2, ..., $11, ..., and $NF) and printf.&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;&lt;BR /&gt;Tom&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 15 Jul 2002 17:35:43 GMT</pubDate>
    <dc:creator>Tom Maloy</dc:creator>
    <dc:date>2002-07-15T17:35:43Z</dc:date>
    <item>
      <title>Script for top.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-top/m-p/2764039#M73131</link>
      <description>Hi All:&lt;BR /&gt;&lt;BR /&gt; I was able to pick up a good script from the forums which i have attached. This picks out the top process(first line) of the top command.&lt;BR /&gt;&lt;BR /&gt;In our case here we sometimes have two application processess eating up CPU and we want to gather some info before killing it.I understand that this script would work for the second process also after the 1st one is killed. But how do i modify it so that it works for 2 top processes?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Joe.</description>
      <pubDate>Mon, 15 Jul 2002 16:45:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-top/m-p/2764039#M73131</guid>
      <dc:creator>joe_91</dc:creator>
      <dc:date>2002-07-15T16:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Script for top.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-top/m-p/2764040#M73132</link>
      <description>First, ask for two processes from top: change the -n1 option to -n2. You may want to use -h as well, to hide multiple CPU output.&lt;BR /&gt;&lt;BR /&gt;Second, change that first awk line from:&lt;BR /&gt;&lt;BR /&gt;# Print PID, CPU usage, username, and process name of single top process&lt;BR /&gt;awk '{if(($1~/CPU/)&amp;amp;&amp;amp;($2~/TTY/)){flg=1;next};if(flg==1){printf("%6s %3.0f %9s %s\n",$3,$11,$4,$NF);flg=0}}' /tmp/xxx &amp;gt;/tmp/yyy&lt;BR /&gt;&lt;BR /&gt;to:&lt;BR /&gt;&lt;BR /&gt;# Print PID, CPU usage, username, and process name of two top processes&lt;BR /&gt;awk '{if(($1~/CPU/)&amp;amp;&amp;amp;($2~/TTY/)){getline; printf("%6s %3.0f %9s %s\n",$3,$11,$4,$NF);getline; printf("%6s %3.0f %9s %s\n",$3,$11,$4,$NF)}' /tmp/xxx &amp;gt;/tmp/yyy&lt;BR /&gt;&lt;BR /&gt;The "if" matches the header line of the data section. "getline" gets the data for the first process, printed with "printf". Repeat getline and printf for the second process.&lt;BR /&gt;&lt;BR /&gt;Tom&lt;BR /&gt;</description>
      <pubDate>Mon, 15 Jul 2002 17:04:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-top/m-p/2764040#M73132</guid>
      <dc:creator>Tom Maloy</dc:creator>
      <dc:date>2002-07-15T17:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Script for top.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-top/m-p/2764041#M73133</link>
      <description>Hi Tom:&lt;BR /&gt;&lt;BR /&gt;  Thanks. Can you explain the awk statement..like what it does??&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Joe.</description>
      <pubDate>Mon, 15 Jul 2002 17:19:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-top/m-p/2764041#M73133</guid>
      <dc:creator>joe_91</dc:creator>
      <dc:date>2002-07-15T17:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Script for top.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-for-top/m-p/2764042#M73134</link>
      <description>Let's look at the whole thing, and break it down into pieces. The whole thing:&lt;BR /&gt;&lt;BR /&gt;awk '{if(($1~/CPU/)&amp;amp;&amp;amp;($2~/TTY/)){getline; printf("%6s %3.0f %9s %s\n",$3,$11,$4,$NF);getline; printf("%6s %3.0f %9s %s\n",$3,$11,$4,$NF)}}' /tmp/xxx &amp;gt;/tmp/yyy&lt;BR /&gt;&lt;BR /&gt;Note that I added one other } before the last ' to close the if statement.&lt;BR /&gt;&lt;BR /&gt;The general form is:&lt;BR /&gt;awk 'pattern{commands}' inputfile &amp;gt; outputfile&lt;BR /&gt;&lt;BR /&gt;So awk is getting its input from /tmp/xxx, and putting its output into /tmp/yyy.&lt;BR /&gt;&lt;BR /&gt;In this awk script, we do not have any of the (optional) patterns. (If patterns were present, then awk would execute to commands if and only if the pattern was matched. I'm sure that we could change this script to use patterns if needed.)&lt;BR /&gt;&lt;BR /&gt;With no patterns, we will execute the commands for every line of input.&lt;BR /&gt;&lt;BR /&gt;The only command is an if statement. If the first parameter of the input line ($1) is "CPU" and the second parameter ($2) is "TTY", then the commands inside the second set of {} will be executed.&lt;BR /&gt;&lt;BR /&gt;getline throws out the current line of data, and gets the next line from the input file. That will be the line containing data for the first process. printf just formats the output. In this case, we are printing out four values: the third ($3), eleventh ($11), fourth (4$), and total number of fields on the line ($NF).&lt;BR /&gt;&lt;BR /&gt;To get the data for the second process, we just repeat the getline (which puts new values in $1, $2, ..., $11, ..., and $NF) and printf.&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;&lt;BR /&gt;Tom&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 15 Jul 2002 17:35:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-for-top/m-p/2764042#M73134</guid>
      <dc:creator>Tom Maloy</dc:creator>
      <dc:date>2002-07-15T17:35:43Z</dc:date>
    </item>
  </channel>
</rss>

