<?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 help .. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778997#M722483</link>
    <description>#cat log|awk -F "-" '{print $1,$2}'|awk -F " " '{print $1,$2}'|uniq&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
    <pubDate>Sat, 03 Aug 2002 06:44:50 GMT</pubDate>
    <dc:creator>T G Manikandan</dc:creator>
    <dc:date>2002-08-03T06:44:50Z</dc:date>
    <item>
      <title>script help ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778993#M722479</link>
      <description>&lt;P&gt;Hello everyone,&lt;BR /&gt;I have been asked to look though several logs and find out how many diffent usernames have been logging in our webserver from the same ip address. &lt;BR /&gt;Here is the format of the logs&lt;BR /&gt;&lt;BR /&gt;xxx.yyy.zzz.252 - martila [02/Aug/2002:13:52:06 -0500] "GET / HTTP/1.0" 304 -&lt;BR /&gt;xxx.yyy.zzz.252 - - [02/Aug/2002:13:52:00 -0500] "GET / HTTP/1.0" 401 223&lt;BR /&gt;xxx.yyy.zzz.252 - delgads [02/Aug/2002:13:52:01 -0500] "GET / HTTP/1.0" 304 -&lt;BR /&gt;xxx.yyy.zzz.197 - - [02/Aug/2002:13:56:51 -0500] "GET / HTTP/1.0" 401 223&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;where the first colum is the ip address and martila and delgads are the usernames.&lt;BR /&gt;I need to be able to show something that will show me&lt;BR /&gt;&lt;BR /&gt;xxx.yyy.zzz.252 martila&lt;BR /&gt;xxx.yyy.zzz.252 otheruser&lt;BR /&gt;xxx.yyy.zzz.252 otheruser1&lt;BR /&gt;&lt;BR /&gt;and so on for all the of ips.&lt;BR /&gt;I tried to filter though them with awk but I am getting stuck on the compare because I will get a big list of the same user from the same ip.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;~ Richard&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. This thread has been movd from HP-UX &amp;gt;&amp;nbsp;System Administration to HP-UX &amp;gt; languages - HP Forums Moderator&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2012 07:11:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778993#M722479</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2012-10-22T07:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: script help ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778994#M722480</link>
      <description>Richard,&lt;BR /&gt;&lt;BR /&gt;Have you tried using the uniq -c command to get your count? If you get the columns with awk that you want, sort them, and then use uniq -c that should be able to give you the numbers you want.&lt;BR /&gt;&lt;BR /&gt;Example: If I have a file that contains the following contents:&lt;BR /&gt;&lt;BR /&gt;10.10.10.1 alice&lt;BR /&gt;10.10.10.2 henry&lt;BR /&gt;10.10.10.2 henry&lt;BR /&gt;10.10.10.2 henry&lt;BR /&gt;10.10.10.3 james&lt;BR /&gt;10.10.10.4 larry&lt;BR /&gt;&lt;BR /&gt;**notice it is already sorted&lt;BR /&gt;&lt;BR /&gt;the run the following command:&lt;BR /&gt;&lt;BR /&gt;#uniq -c testfile.txt  (assuming testfile.txt is the name of the file you are checking for duplicates)&lt;BR /&gt;&lt;BR /&gt;You will get an output similar to the following:&lt;BR /&gt;&lt;BR /&gt;# uniq -c testfile.txt&lt;BR /&gt;   1 10.10.10.1 alice&lt;BR /&gt;   3 10.10.10.2 henry&lt;BR /&gt;   1 10.10.10.3 james&lt;BR /&gt;   1 10.10.10.4 larry&lt;BR /&gt;&lt;BR /&gt;I think that addresses your question. Hope it helps.&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Aug 2002 21:39:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778994#M722480</guid>
      <dc:creator>Jeffrey S. Sims</dc:creator>
      <dc:date>2002-08-02T21:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: script help ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778995#M722481</link>
      <description>&lt;BR /&gt;Richard,&lt;BR /&gt;&lt;BR /&gt;Are you able to "parse" out the IP's and usernames? Jeffery has a great hint on getting "counts".&lt;BR /&gt;&lt;BR /&gt;Having been asked to do the same thing from my marketing group quite a while ago, I explained to these idiots (marketing people) (side note: marketing people are people that can't sell), that matching on IP's is equal to asking how many Susan's drive Camery's -&amp;gt; it's a useless meaningless statistic, because users can have the same IP. My IP on my cable modem is NOT the IP that is used when I visit a web site - it's proxied.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Fri, 02 Aug 2002 23:13:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778995#M722481</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-08-02T23:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: script help ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778996#M722482</link>
      <description>perl -nle 'm/^([\d.]+)\s*-\s*(\w+)/&amp;amp;&amp;amp;$who{$1}{$2}++}END{for$ip(sort keys%who){for$n(sort keys%{$who{$ip}}){printf"%4d %16s %s",$who{$ip}{$n},$ip,$n' logfile&lt;BR /&gt;&lt;BR /&gt;WARNING, not tested, just written down</description>
      <pubDate>Sat, 03 Aug 2002 06:30:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778996#M722482</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-08-03T06:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: script help ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778997#M722483</link>
      <description>#cat log|awk -F "-" '{print $1,$2}'|awk -F " " '{print $1,$2}'|uniq&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Sat, 03 Aug 2002 06:44:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778997#M722483</guid>
      <dc:creator>T G Manikandan</dc:creator>
      <dc:date>2002-08-03T06:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: script help ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778998#M722484</link>
      <description>Richard&lt;BR /&gt;&lt;BR /&gt;Some of the above answere may do what you want.  But my understanding of the problem is that if 3 people log in from 193.164.1.23 you want to see&lt;BR /&gt;&lt;BR /&gt;193.164.1.23 mary jane billy&lt;BR /&gt;193.164.1.252 matilda&lt;BR /&gt;&lt;BR /&gt;Furthur to this, you probably do not care if mary logged in 20 times on 193.164.1.23.&lt;BR /&gt;&lt;BR /&gt;That being the case perl would be the best tool for this, but I do not have my Unix computer to do the necessary (I would form a double hash table of the IP's and user names simply incrementing the variable e.g [$ip,$name]= [$ip,$name] + 1)&lt;BR /&gt;&lt;BR /&gt;In ksh/awk I would do a double pass&lt;BR /&gt;&lt;BR /&gt;awk '{print $1}' logfile | sort | uniq &amp;gt; IP-out&lt;BR /&gt;&amp;gt; results&lt;BR /&gt;for ip in $(cat IP-out)&lt;BR /&gt;do&lt;BR /&gt;  awk '$1==IP{print $3}' IP=$ip logfile | sort | uniq &amp;gt; tmp-name&lt;BR /&gt;  echo "$ip" &amp;gt;&amp;gt; results&lt;BR /&gt;  cat tmp-name &amp;gt;&amp;gt; results&lt;BR /&gt;done&lt;BR /&gt;  &lt;BR /&gt;If you want to know how many times each user logged in on the IP use .....uniq -c &amp;gt; tmp-name&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Tim&lt;BR /&gt;</description>
      <pubDate>Sat, 03 Aug 2002 08:52:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778998#M722484</guid>
      <dc:creator>Tim D Fulford</dc:creator>
      <dc:date>2002-08-03T08:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: script help ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778999#M722485</link>
      <description>perl -nle 'm/^([\d.]+)\s*-\s*(\w+)/&amp;amp;&amp;amp;$who{$1}{$2}++}END{for$ip(sort keys%who){printf"%16s ",$ip;for$n(sort keys%{$who{$ip}}){print" $n ($who{$ip}{$n})}}' logfile&lt;BR /&gt;&lt;BR /&gt;To do it like&lt;BR /&gt;&lt;BR /&gt;101.101.101.252 sandra (3) fernandus (8)&lt;BR /&gt;&lt;BR /&gt;my first example also lacks some traling '}'s before the final closing quote. Sorry</description>
      <pubDate>Sat, 03 Aug 2002 12:58:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2778999#M722485</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-08-03T12:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: script help ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2779000#M722486</link>
      <description>Richard:&lt;BR /&gt;&lt;BR /&gt;Almost looks like you have started your own obfuscate Perl contest...&lt;BR /&gt;&lt;BR /&gt;I still like awk(1), mostly because I have successfully avoided working with other platforms (read non-UNIX junk).&lt;BR /&gt;&lt;BR /&gt;Anyhow, lets start with a simple count of how many times an IP appears, and grow from there:&lt;BR /&gt;&lt;BR /&gt;    /^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/ {IPS[$1]+=1}&lt;BR /&gt;    END { for (i in IPS) print I,IPS[I]}&lt;BR /&gt;&lt;BR /&gt;This demonstrates that we can use a string as an array reference.  Now, lets shoot for a two-dimensional array.  Before we begin, I plan on using two other arrays to keep track of the sub-scripts.  This regular expression matches any line that starts with something that looks like an IP address.  You may need to match on other data in the line to have hits only on lines for HTTP connections.  I will also leave off the regular expression that finds an IP address at the head of the line for this next example.&lt;BR /&gt;&lt;BR /&gt;    { DATA[$1","$2]+=1 ; IPS[$1]+=1 ; NAMES[$2]+=1 }&lt;BR /&gt;    END {&lt;BR /&gt;        for (I in IPS)&lt;BR /&gt;            {&lt;BR /&gt;            printf("%s ",I)&lt;BR /&gt;            for (J in NAMES)&lt;BR /&gt;                {&lt;BR /&gt;                if (DATA[I","J] &amp;gt; 0)&lt;BR /&gt;                    printf("%s(%s),"I,DATA[I","J]&lt;BR /&gt;                }&lt;BR /&gt;            printf("\n")&lt;BR /&gt;            }&lt;BR /&gt;        }&lt;BR /&gt;&lt;BR /&gt;In awk, an array reference never points to nothing, but if the reference doesn't exist, it is automagically null (zero).&lt;BR /&gt;&lt;BR /&gt;-dlt-&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 04 Aug 2002 02:56:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2779000#M722486</guid>
      <dc:creator>David Totsch</dc:creator>
      <dc:date>2002-08-04T02:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: script help ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2779001#M722487</link>
      <description>Hi Richard,&lt;BR /&gt;&lt;BR /&gt;I could also contribute my humble version of access_log Perl parser, but refrain from because there is such abundance of  ready log parsers available that I rather would like to point you to the excellent Perl CGI tutorial by Lincoln Stein (who is the author of the Perl CGI.pm module:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://stein.cshl.org/~lstein/talks/perl/perl98.html#Log_Parsing" target="_blank"&gt;http://stein.cshl.org/~lstein/talks/perl/perl98.html#Log_Parsing&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;n.b. Procura's one-liner indeed could scare off the casual Perl scriptor, and looks a bit like a candidate for the renown "Obfuscated Perl Contest".&lt;BR /&gt;If you are interested in some Perl obfuscation, please have a look at this:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.sysadminmag.com/tpj/obfuscated/" target="_blank"&gt;http://www.sysadminmag.com/tpj/obfuscated/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Ralph</description>
      <pubDate>Mon, 05 Aug 2002 07:23:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2779001#M722487</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2002-08-05T07:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: script help ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2779002#M722488</link>
      <description>But in fact it isn't obfuscated at all, just condensed. Let's split it up with some comments. Whitespace is dropped by the forum, so indent and lineouts are void&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;perl -nle '&lt;BR /&gt;# the -n option places the complete -e&lt;BR /&gt;# block in between 'while (&amp;lt;&amp;gt;) { ..-e block ..}'&lt;BR /&gt;m/^([\d.]+) # match ip&lt;BR /&gt;\s* - \s* # mach separator&lt;BR /&gt;(\w+) # match user&lt;BR /&gt;/x&lt;BR /&gt;&amp;amp;&amp;amp; # if matched&lt;BR /&gt;$who{$1}{$2}++; # count in hash of hahses $1 = ip, $2 = user&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;# at the end of processing ...&lt;BR /&gt;&lt;BR /&gt;END{&lt;BR /&gt;for $ip (sort keys%who) { # iterate over sorted IP's&lt;BR /&gt;printf"%16s ",$ip; # and print it aligned&lt;BR /&gt;for $n (sort keys%{$who{$ip}}) { # iterate over the names for this IP&lt;BR /&gt;print" $n ($who{$ip}{$n})"; # and print with count&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;' logfile&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Along the way I noticed a missing double quote for the final print. Sorry.</description>
      <pubDate>Mon, 05 Aug 2002 08:30:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/2779002#M722488</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-08-05T08:30:31Z</dc:date>
    </item>
  </channel>
</rss>

