<?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: how to assing value in script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-assing-value-in-script/m-p/4149227#M725845</link>
    <description>this is my script , I modified the line awk of james.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;clear&lt;BR /&gt;for i in `cat switchs|awk '{print $1}'`&lt;BR /&gt;do&lt;BR /&gt;echo "Connecting $i...."&lt;BR /&gt;#echo "statsclear"&lt;BR /&gt; FLG=0&lt;BR /&gt; while [ $FLG -le 60 ] #600&lt;BR /&gt; do&lt;BR /&gt;    (sleep 1;echo admin;sleep 1 ;echo password;sleep 1 ;echo "statsclear" ;echo "porterrshow" ;sleep 2&lt;BR /&gt;"exit")|telnet $i &amp;gt; /frames/logcrc&lt;BR /&gt;   awk 'NR&amp;gt;13 {if ($5~/k/) {F1=$5*1024} else {F12=$5};SUM+=F12;if (F12&amp;gt;0) {print&lt;BR /&gt;$1,$5}};END{print "TOTAL CRCERROR", SUM}' /frames/logcrc &amp;gt; /frames/logcrc.1&lt;BR /&gt;  FLG=`expr $FLG + 1`&lt;BR /&gt;  sleep 1 #300&lt;BR /&gt; done&lt;BR /&gt;done</description>
    <pubDate>Mon, 25 Feb 2008 13:58:06 GMT</pubDate>
    <dc:creator>Jairo Campana</dc:creator>
    <dc:date>2008-02-25T13:58:06Z</dc:date>
    <item>
      <title>how to assing value in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-assing-value-in-script/m-p/4149225#M725843</link>
      <description>Hi , i have a script , the results is a value numeric , this value is sent to a file&lt;BR /&gt;port 1 :0&lt;BR /&gt;port 5: 21&lt;BR /&gt;port 10: 5&lt;BR /&gt;&lt;BR /&gt;I want assign to this value and the next time compare if change or increase for this port.&lt;BR /&gt;&lt;BR /&gt;the port begin in 0.&lt;BR /&gt;&lt;BR /&gt;for port 5:  21 &lt;BR /&gt; the value compare is 21 , this port increase in X interval time .&lt;BR /&gt;&lt;BR /&gt;a need the next time a need to know  how much the value grows &lt;BR /&gt;</description>
      <pubDate>Fri, 22 Feb 2008 20:09:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-assing-value-in-script/m-p/4149225#M725843</guid>
      <dc:creator>Jairo Campana</dc:creator>
      <dc:date>2008-02-22T20:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to assing value in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-assing-value-in-script/m-p/4149226#M725844</link>
      <description>&lt;!--!*#--&gt;Jairo, &lt;BR /&gt;&lt;BR /&gt;That's a very confusing description. Please re-read. &lt;BR /&gt;But I think I know what you are getting at.&lt;BR /&gt;&lt;BR /&gt;Does the data really sometimes have a space before the ':' and a space sometimes after it ?&lt;BR /&gt;&lt;BR /&gt;Does each port appear every time?&lt;BR /&gt;&lt;BR /&gt;Let's say you simply have an 'old' and a 'new' file. Each looks like your example, but no spaces around that ':'.&lt;BR /&gt;&lt;BR /&gt;#cat old&lt;BR /&gt;port 1:0&lt;BR /&gt;port 5:21&lt;BR /&gt;port 10:5&lt;BR /&gt;&lt;BR /&gt;#cat new&lt;BR /&gt;port 1:0&lt;BR /&gt;port 5:23&lt;BR /&gt;port 10:4&lt;BR /&gt;&lt;BR /&gt;In order to 'subtract' those files, we need to remember the values of one of them.&lt;BR /&gt;&lt;BR /&gt;We can do this in for example awk.&lt;BR /&gt;&lt;BR /&gt;Before we start the real work, let's first try to get the data into an array and back in the BEGIN block for awk.&lt;BR /&gt;&lt;BR /&gt;$ awk 'BEGIN {while (getline &amp;lt;"old"){split ($0,tmp,"[ :]");old[tmp[2]]=tmp[3]} for (port in old){print port "-&amp;gt;" old[port]}}'&lt;BR /&gt;5-&amp;gt;21&lt;BR /&gt;10-&amp;gt;5&lt;BR /&gt;1-&amp;gt;0&lt;BR /&gt;&lt;BR /&gt;Yeah! &lt;BR /&gt;Now add reading the new file&lt;BR /&gt;&lt;BR /&gt;$ cat port_diff.awk&lt;BR /&gt;BEGIN {&lt;BR /&gt;  while (getline &amp;lt;"old"){&lt;BR /&gt;    split ($0,tmp,"[ :]");&lt;BR /&gt;    old[tmp[2]]=tmp[3]&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;{ split ($0,tmp,"[ :]");&lt;BR /&gt;  new = tmp[3]&lt;BR /&gt;  if (tmp[2] in old) {&lt;BR /&gt;    o = old[tmp[2]];&lt;BR /&gt;    x = "";&lt;BR /&gt;  } else {&lt;BR /&gt;    o = 0;&lt;BR /&gt;    x = " New!"&lt;BR /&gt;  }&lt;BR /&gt;  printf ("port %2d : %4d %4s\n", tmp[2], new, (o==new)? "" : new - o);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;$ awk -f port_diff.awk new&lt;BR /&gt;port  1 :    0&lt;BR /&gt;port  5 :   23    2&lt;BR /&gt;port 10 :    4   -1&lt;BR /&gt;&lt;BR /&gt;Yeah Yeah!&lt;BR /&gt;&lt;BR /&gt;All that is needed now is a script to get old an new done right.&lt;BR /&gt;Outline:&lt;BR /&gt;&lt;BR /&gt;touch new&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt; mv new old&lt;BR /&gt; my-tool &amp;gt; new&lt;BR /&gt; awk -f port_diff.awk new&lt;BR /&gt; sleep 10&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But wait... there is more...&lt;BR /&gt;&lt;BR /&gt;It sounds like you have control over the data generation. Correct?&lt;BR /&gt;&lt;BR /&gt;Might I recomment an XML format, or something readily parseable for example SCV file with a line per report period:&lt;BR /&gt;&lt;BR /&gt;time,port#:value,port#:value,...&lt;BR /&gt;Data example&lt;BR /&gt;22:10:02,1:0,5:21,10:5&lt;BR /&gt;22:20:02,1:0,5:23,10:4&lt;BR /&gt;&lt;BR /&gt;or if ports are a tight range 0..X&lt;BR /&gt;time,value0,value1,value2,...&lt;BR /&gt;&lt;BR /&gt;Now lets assume the application does an append to the data file for each cycle.&lt;BR /&gt;Idealy it would time-stamp it, but lets just use a line with ----- as seperator.&lt;BR /&gt;for example:&lt;BR /&gt;&lt;BR /&gt;#cat data&lt;BR /&gt;port 1:0&lt;BR /&gt;port 5:21&lt;BR /&gt;port 10:5&lt;BR /&gt;-----&lt;BR /&gt;port 1:0&lt;BR /&gt;port 5:20&lt;BR /&gt;port 10:15&lt;BR /&gt;-----&lt;BR /&gt;port 1:2&lt;BR /&gt;port 5:15&lt;BR /&gt;port 10:25&lt;BR /&gt;-----&lt;BR /&gt;port 1:3&lt;BR /&gt;port 5:21&lt;BR /&gt;port 10:35&lt;BR /&gt;-----&lt;BR /&gt;port 1:5&lt;BR /&gt;port 5:21&lt;BR /&gt;port 10:35&lt;BR /&gt;-----&lt;BR /&gt;&lt;BR /&gt;Now let's tackle this with perl:&lt;BR /&gt;&lt;BR /&gt;#cat port_diff.pl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my ($old, $new, $tmp, $port, %data_1, %data_2);&lt;BR /&gt;$old = \%data_1; # Array reference&lt;BR /&gt;$new = \%data_2;&lt;BR /&gt;while (&amp;lt;&amp;gt;) { # process input&lt;BR /&gt;&lt;BR /&gt;  s/\s//g; # strip whitespace&lt;BR /&gt;&lt;BR /&gt;  $$new{$1} = $2 if (/port(\d+):(\d+)/) ; # portNN:NN&lt;BR /&gt;&lt;BR /&gt;  if (m|-*.*-|m) {        # seperator line?&lt;BR /&gt;    foreach $port (sort {$a &amp;lt;=&amp;gt; $b} keys %$old) {&lt;BR /&gt;      my $n = $$new{$port};&lt;BR /&gt;      my $o = $$old{$port};&lt;BR /&gt;      printf "port %2d %4d %4s\n", $port, $n, ($n==$o)? '': $n-$o;&lt;BR /&gt;    }&lt;BR /&gt;    print qq(\n);&lt;BR /&gt;    $tmp = $old; # old shall be new and new shall be old.&lt;BR /&gt;    $old = $new;&lt;BR /&gt;    $new = $tmp;&lt;BR /&gt;    next&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;#perl port_diff.pl data&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;port  1    0&lt;BR /&gt;port  5   20   -1&lt;BR /&gt;port 10   15   10&lt;BR /&gt;&lt;BR /&gt;port  1    2    2&lt;BR /&gt;port  5   15   -5&lt;BR /&gt;port 10   25   10&lt;BR /&gt;&lt;BR /&gt;port  1    3    1&lt;BR /&gt;port  5   21    6&lt;BR /&gt;port 10   35   10&lt;BR /&gt;&lt;BR /&gt;port  1    5    2&lt;BR /&gt;port  5   21&lt;BR /&gt;port 10   35&lt;BR /&gt;&lt;BR /&gt;yeah yeah yeah!&lt;BR /&gt;&lt;BR /&gt;So this perl uses two arrays data-1 and data-2 which are 'flipped' every time we read a chunk of data when a line of dashes is seen.&lt;BR /&gt;Btw.. normal folks would use if /----/ for that match.&lt;BR /&gt;And real tight programmers would use /^-+$/&lt;BR /&gt;:-)&lt;BR /&gt;&lt;BR /&gt;When a data line is matched, we add an element to the data array pointed to by $new, using the port as key, value as data.&lt;BR /&gt;&lt;BR /&gt;When that seperator line is seen, we retrieve the ports which are the keys for the data array pointed to by $old and sort them numerically with an inline function { $a &amp;lt;=&amp;gt; $ b }. Then we pick up the old and new values in variables (optional... just reads and writes easier).&lt;BR /&gt;And print the port, data and difference.&lt;BR /&gt;&lt;BR /&gt;I could have used the use the keys for %$new. That's mcuh the same, except for the first dta chunk for which there are no old values yet. because they not exist for the first data chunk. We could also pretend there is a non-existent initial chunk with all port values 0. &lt;BR /&gt;That code could look like:&lt;BR /&gt;:&lt;BR /&gt;    foreach $port (sort {$a &amp;lt;=&amp;gt; $b} keys %$new) {&lt;BR /&gt;      my $n = $$new{$port};&lt;BR /&gt;      my $o = $$old{$port};&lt;BR /&gt;      $o = 0 unless $o;&lt;BR /&gt;:&lt;BR /&gt;&lt;BR /&gt;And the output will start with:&lt;BR /&gt;&lt;BR /&gt;port  1    0&lt;BR /&gt;port  5   21   21&lt;BR /&gt;port 10    5    5&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;'nuff for 1 lesson!&lt;BR /&gt;More over... my beer bottle is empty... you owe me one.&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 23 Feb 2008 06:20:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-assing-value-in-script/m-p/4149226#M725844</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-02-23T06:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to assing value in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-assing-value-in-script/m-p/4149227#M725845</link>
      <description>this is my script , I modified the line awk of james.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;clear&lt;BR /&gt;for i in `cat switchs|awk '{print $1}'`&lt;BR /&gt;do&lt;BR /&gt;echo "Connecting $i...."&lt;BR /&gt;#echo "statsclear"&lt;BR /&gt; FLG=0&lt;BR /&gt; while [ $FLG -le 60 ] #600&lt;BR /&gt; do&lt;BR /&gt;    (sleep 1;echo admin;sleep 1 ;echo password;sleep 1 ;echo "statsclear" ;echo "porterrshow" ;sleep 2&lt;BR /&gt;"exit")|telnet $i &amp;gt; /frames/logcrc&lt;BR /&gt;   awk 'NR&amp;gt;13 {if ($5~/k/) {F1=$5*1024} else {F12=$5};SUM+=F12;if (F12&amp;gt;0) {print&lt;BR /&gt;$1,$5}};END{print "TOTAL CRCERROR", SUM}' /frames/logcrc &amp;gt; /frames/logcrc.1&lt;BR /&gt;  FLG=`expr $FLG + 1`&lt;BR /&gt;  sleep 1 #300&lt;BR /&gt; done&lt;BR /&gt;done</description>
      <pubDate>Mon, 25 Feb 2008 13:58:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-assing-value-in-script/m-p/4149227#M725845</guid>
      <dc:creator>Jairo Campana</dc:creator>
      <dc:date>2008-02-25T13:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to assing value in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-assing-value-in-script/m-p/4149228#M725846</link>
      <description>the ouput in my sccript is of each switch porterrshow, before make one statsclear&lt;BR /&gt;&lt;BR /&gt;233: 1&lt;BR /&gt;TOTAL CRCERROR 1</description>
      <pubDate>Mon, 25 Feb 2008 14:04:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-assing-value-in-script/m-p/4149228#M725846</guid>
      <dc:creator>Jairo Campana</dc:creator>
      <dc:date>2008-02-25T14:04:52Z</dc:date>
    </item>
  </channel>
</rss>

