<?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: scripting help in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912238#M96881</link>
    <description>Chris,&lt;BR /&gt;insert after your&lt;BR /&gt;print $ip "has ..."&lt;BR /&gt;&lt;BR /&gt;the line&lt;BR /&gt; grep $ip $frep | uniq -c |  awk '{print "user "$12" failed "$1" times"}'&lt;BR /&gt;&lt;BR /&gt;Relies on same assumption as your grep for COUNT.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 13 Dec 2006 07:03:47 GMT</pubDate>
    <dc:creator>Peter Godron</dc:creator>
    <dc:date>2006-12-13T07:03:47Z</dc:date>
    <item>
      <title>scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912236#M96879</link>
      <description>I am attempting to gather some information from a logfile but am struggling with displaying all the info I require, my logfile looks like this:&lt;BR /&gt;&lt;BR /&gt;Dec 12 08:15:11 &lt;SERVER&gt; syslog: pts/182: failed login attempt for &lt;USER&gt; from &lt;IP&gt;&lt;BR /&gt;&lt;BR /&gt;I created the below script which displays some of the info I require:&lt;BR /&gt;&lt;BR /&gt;# set environment&lt;BR /&gt;&lt;BR /&gt;frep=/home/sysadmcl/scripts/build/fail.rep&lt;BR /&gt;logrep=/home/sysadmcl/scripts/build/failed.out&lt;BR /&gt;fout=/home/sysadmcl/scripts/build/failed.count&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;        for i in `awk '{print $13}' $frep |sort -u`&lt;BR /&gt;        do&lt;BR /&gt;&lt;BR /&gt;        COUNT=`grep $i $frep |wc -l`&lt;BR /&gt;&lt;BR /&gt;                print $i $COUNT&lt;BR /&gt;&lt;BR /&gt;        done &amp;gt; $fout&lt;BR /&gt;&lt;BR /&gt;                        while read ip num&lt;BR /&gt;                        do&lt;BR /&gt;                                if [ $num -gt 3 ] ; then&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                                print $ip "has an unexceptable number of failed logins of" $num "attempts"&lt;BR /&gt;&lt;BR /&gt;                                fi&lt;BR /&gt;&lt;BR /&gt;                        done &amp;lt; $fout&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;--&amp;gt; ./check_sec.sc  &lt;BR /&gt;&lt;IP&gt; has an unexceptable number of failed logins of 4 attempts&lt;BR /&gt;&lt;IP&gt; has an unexceptable number of failed logins of 5 attempts&lt;BR /&gt;&lt;BR /&gt;This works great however can someone help me by getting the script to display each user that has failed from each ip eg:&lt;BR /&gt;--&amp;gt; ./check_sec.sc  &lt;BR /&gt;&lt;IP&gt; has an unexceptable number of failed logins of 4 attempts&lt;BR /&gt;&lt;USER&gt; failed x times&lt;BR /&gt;&lt;USER&gt; faield x times&lt;BR /&gt;&lt;BR /&gt;&lt;IP&gt; has an unexceptable number of failed logins of 5 attempts&lt;BR /&gt;&lt;USER&gt; failed x times&lt;BR /&gt;&lt;BR /&gt;I am sure the solution is pretty simple but I just can get it.&lt;BR /&gt;&lt;BR /&gt;Thanks guys.&lt;BR /&gt;&lt;BR /&gt;Chris.&lt;/USER&gt;&lt;/IP&gt;&lt;/USER&gt;&lt;/USER&gt;&lt;/IP&gt;&lt;/IP&gt;&lt;/IP&gt;&lt;/IP&gt;&lt;/USER&gt;&lt;/SERVER&gt;</description>
      <pubDate>Wed, 13 Dec 2006 06:17:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912236#M96879</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2006-12-13T06:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912237#M96880</link>
      <description>&lt;!--!*#--&gt;--8&amp;lt;--- untested braindump&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;my $frep = "/home/sysadmcl/scripts/build/fail.rep";&lt;BR /&gt;my $logrep = "/home/sysadmcl/scripts/build/failed.out";&lt;BR /&gt;my $fout = "/home/sysadmcl/scripts/build/failed.count";&lt;BR /&gt;&lt;BR /&gt;my %fail;&lt;BR /&gt;{   local @ARGV = ($frep);&lt;BR /&gt;    while (&amp;lt;&amp;gt;) {&lt;BR /&gt;        m{failed login attempt for\s+(.*?)\s+from\s+(\S+)} or next;&lt;BR /&gt;        $fail{$2}{$1}++;&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;&lt;BR /&gt;foreach my $ip (sort keys %fail) {&lt;BR /&gt;    my ($n, @fail) = (0);&lt;BR /&gt;    foreach my $user (sort keys %{$fail{$ip}}) {&lt;BR /&gt;        (my $f = $fail{$ip}{$user}) &amp;lt;= 2 and next;&lt;BR /&gt;        push @fail, [ $user, $f ];&lt;BR /&gt;        $n += $f;&lt;BR /&gt;        }&lt;BR /&gt;    @fail or next;&lt;BR /&gt;    print "$ip as an unexceptable number of $n failed logins:\n";&lt;BR /&gt;    print "  ", $_-&amp;gt;[0], " failed ", $_-&amp;gt;[1], " times\n" for @fail;&lt;BR /&gt;    }&lt;BR /&gt;--&amp;gt;8---&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Wed, 13 Dec 2006 06:51:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912237#M96880</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-12-13T06:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912238#M96881</link>
      <description>Chris,&lt;BR /&gt;insert after your&lt;BR /&gt;print $ip "has ..."&lt;BR /&gt;&lt;BR /&gt;the line&lt;BR /&gt; grep $ip $frep | uniq -c |  awk '{print "user "$12" failed "$1" times"}'&lt;BR /&gt;&lt;BR /&gt;Relies on same assumption as your grep for COUNT.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Dec 2006 07:03:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912238#M96881</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-12-13T07:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912239#M96882</link>
      <description>Thanks guys,&lt;BR /&gt;&lt;BR /&gt;as I dont know the world of perl yet I choose not to use the sytax however thanks for the idea.&lt;BR /&gt;&lt;BR /&gt;Peter, I used your solution ( or a variation of it) and works great:&lt;BR /&gt;&lt;BR /&gt;# set environment&lt;BR /&gt;&lt;BR /&gt;frep=/home/scripts/build/fail.rep&lt;BR /&gt;logrep=/home/scripts/build/failed.out&lt;BR /&gt;fout=/home/scripts/build/failed.count&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;        for i in `awk '{print $13}' $frep |sort -u`&lt;BR /&gt;        do&lt;BR /&gt;&lt;BR /&gt;        COUNT=`grep $i $frep |wc -l`&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                print $i $COUNT&lt;BR /&gt;&lt;BR /&gt;        done &amp;gt; $fout&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                        while read ip num&lt;BR /&gt;                        do&lt;BR /&gt;                                if [ $num -gt 3 ] ; then&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                                echo "------------------------------------------------------------------"&lt;BR /&gt;                                print "$ip an unaccceptable number of failed logins of" $num "attempts\n"&lt;BR /&gt;                                grep $ip $frep |awk '{print $11,$13}' |uniq -c |awk '{print "user " $2" failed " $1 " times"}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                                fi&lt;BR /&gt;&lt;BR /&gt;                        done &amp;lt; $fout&lt;BR /&gt;&lt;BR /&gt;                                echo "------------------------------------------------------------------"&lt;BR /&gt;&lt;BR /&gt;now I would like to see if I can make the script more efficient by either using arrays or awk.&lt;BR /&gt;&lt;BR /&gt;any feedback would be great for my future scripts .....&lt;BR /&gt;&lt;BR /&gt;cheers&lt;BR /&gt;&lt;BR /&gt;output of script:&lt;BR /&gt;&lt;BR /&gt;--&amp;gt; ./check_sec.sc &lt;BR /&gt;------------------------------------------------------------------&lt;BR /&gt;&lt;IP&gt; an unacceptable number of failed logins of 4 attempts&lt;BR /&gt;&lt;BR /&gt;user x failed 2 times&lt;BR /&gt;user UNKNOWN_USER failed 1 times&lt;BR /&gt;user y failed 1 times&lt;BR /&gt;------------------------------------------------------------------&lt;BR /&gt;&lt;IP&gt; an unexceptable number of failed logins of 5 attempts&lt;BR /&gt;&lt;BR /&gt;user a failed 4 times&lt;BR /&gt;user b failed 1 times&lt;BR /&gt;------------------------------------------------------------------&lt;/IP&gt;&lt;/IP&gt;</description>
      <pubDate>Wed, 13 Dec 2006 09:32:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912239#M96882</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2006-12-13T09:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912240#M96883</link>
      <description>&amp;gt;&amp;gt;&amp;gt; any feedback would be great for my future scripts .....&lt;BR /&gt;&lt;BR /&gt;With that in mind:&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; as I dont know the world of perl yet I choose not to use the sytax however thanks for the idea.&lt;BR /&gt;&lt;BR /&gt;Please reconsider. &lt;BR /&gt;It gets the job done, it will be fast, and Procura is the best in space.&lt;BR /&gt;Read for 5 minutes and see that you can mainitain/alter it as needed.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; now I would like to see if I can make the script more efficient by either using arrays or awk.&lt;BR /&gt;&lt;BR /&gt;That's what the perl code does, better than awk could.&lt;BR /&gt;&lt;BR /&gt;Take this script as an excuse to pick up perl. Read this forum and other notes and keep your eyes open for other (more simple) perl scripts. You'll never look back!&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Dec 2006 09:38:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912240#M96883</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-12-13T09:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912241#M96884</link>
      <description>appreciate your comments Hein but in the world of sysadm and server support it is quite difficult to progress with perl and other programming ....&lt;BR /&gt;&lt;BR /&gt;especially when technologies are always advancing and theres always so much to learn.&lt;BR /&gt;&lt;BR /&gt;one day maybe I will get some time to develop my scripting skills..&lt;BR /&gt;&lt;BR /&gt;o(+_+)o&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Wed, 13 Dec 2006 09:46:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912241#M96884</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2006-12-13T09:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912242#M96885</link>
      <description>Hi Chris:&lt;BR /&gt;&lt;BR /&gt;I see "red flags" whenever I see a pipeline that has 'grep' followed by 'awk'.  There is no need to spawn a separate process ('grep') when 'awk' can do the pattern matching, extraction and formatting.&lt;BR /&gt;&lt;BR /&gt;At least, change:&lt;BR /&gt;&lt;BR /&gt;# grep $ip $frep |awk '{print $11,$13}' |uniq -c|awk '{print "user " $2" failed " $1 " times"}'&lt;BR /&gt;&lt;BR /&gt;...to:&lt;BR /&gt;&lt;BR /&gt;# awk -v ip=${ip} '{if ($0~ip) {print $11,$13}}' ${frep}|uniq -c|awk '{print "user " $2" failed " $1 " times"}'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Dec 2006 11:08:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912242#M96885</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-12-13T11:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912243#M96886</link>
      <description>Thanks James,&lt;BR /&gt;&lt;BR /&gt;Just what I was looking for ...&lt;BR /&gt;&lt;BR /&gt;I will consider this going forward.&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Wed, 13 Dec 2006 11:13:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-help/m-p/3912243#M96886</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2006-12-13T11:13:34Z</dc:date>
    </item>
  </channel>
</rss>

