Good afternoon.The second day I dig with the script, I can not figure out how to make a condition in the condition.

There is a log file in which user actions are logged, bots come in, the bot performs a task sequence in one second, that is, log in, change the password, log out.
 I'm trying to write a script that will determine the bot, but I ran into such a problem, how to fit the condition into the condition, so you can not do it in the bash? If so, can you advise something on how to implement such a script?

This is what I did:
#!/Bin/bash

read -p"Please enter filename:" filename;
count=`cat $filename | awk {'print $6'} | cut -c 21- | rev | cut -c 2- | rev | uniq | wc -l`
allusers=`cat $filename | awk {'print $6'} | cut -c 21- | rev | cut -c 2- | rev | uniq`
action=`cat $filename | awk {'print $8, $9, $10'} | cut -c 2- | rev | cut -c 2- | rev`
#countact=`cat $filename | grep"$username" | awk {'print $6'} | cut -c 21- | rev | cut -c 2- | rev | wc -l`
for((i=1;i<="$count";i ++));
do
        username=`cat $filename | awk {'print $6'} | cut -c 21- | rev | cut -c 2- | rev | uniq | sed -n"$i" p`
        firstop=`cat $filename | grep"$username" | awk'{print $5}'| head -n1 | cut -c 7-8`
        lastop=`cat $filename | grep"$username" | awk'{print $5}'| tail -1 | cut -c 7-8`
        countact=`cat $filename | grep"$username" | awk {'print $6'} | cut -c 21- | rev | cut -c 2- | rev | wc -l`
#####ACTIONS
        action1=`cat $filename | grep"$username" | awk {'Print $8, $9, $10'} | cut -c 2- | rev | cut -c 2- | rev | sed -n 1p`
        action2=`cat $filename | grep"$username" | awk {'Print $8, $9, $10'} | cut -c 2- | rev | cut -c 2- | rev | sed -n 2p`
        action3=`cat $filename | grep"$username" | awk {'Print $8, $9, $10'} | cut -c 2- | rev | cut -c 2- | rev | sed -n 3p`
        act1="user logged in"
        act2="user changed password"
        act3="user logged off"
        if[$countact=3];then

                if[$firstop=$lastop];then

                                if[$action1=$act1];then

                                        if[$action2=$act2];then

                                                if[$action3=$act3];then

                                                 echo $username"- BOT"

                                                fi

                                        fi

                                fi
                fi
                else
                echo $username"- NOT BOT"
        fi
done


Here is a piece of the log:
Mon, 22 Aug 2016 13:15:39 +0200 | 178.57.66.225 | fxsciaqulmlk | - | user logged in | -
Mon, 22 Aug 2016 13:15:39 +0200 | 178.57.66.225 | fxsciaqulmlk | - | user changed password | -
Mon, 22 Aug 2016 13:15:39 +0200 | 178.57.66.225 | fxsciaqulmlk | - | user logged off | -
Mon, 22 Aug 2016 13:15:42 +0200 | 178.57.66.225 | faaaaaa11111 | - | user logged in | -
Mon, 22 Aug 2016 13:15:40 +0200 | 178.57.66.215 | terdsfsdfsdf | - | user logged in | -
Mon, 22 Aug 2016 13:15:49 +0200 | 178.57.66.215 | terdsfsdfsdf | - | user changed password | -
Mon, 22 Aug 2016 13:15:49 +0200 | 178.57.66.215 | terdsfsdfsdf | - | user logged off | -
Mon, 22 Aug 2016 13:15:59 +0200 | 178.57.66.205 | erdsfsdfsdf | - | user logged in | -
Mon, 22 Aug 2016 13:15:59 +0200 | 178.57.66.205 | erdsfsdfsdf | - | user logged in | -
Mon, 22 Aug 2016 13:15:59 +0200 | 178.57.66.205 | erdsfsdfsdf | - | user changed password | -
Mon, 22 Aug 2016 13:15:59 +0200 | 178.57.66.205 | erdsfsdfsdf | - | user logged off | -
Mon, 22 Aug 2016 13:17:50 +0200 | 178.57.66.205 | abcbbabab | - | user logged in | -
Mon, 22 Aug 2016 13:17:50 +0200 | 178.57.66.205 | abcbbabab | - | user changed password | -
Mon, 22 Aug 2016 13:17:50 +0200 | 178.57.66.205 | abcbbabab | - | user changed profile | -
Mon, 22 Aug 2016 13:17:50 +0200 | 178.57.66.205 | abcbbabab | - | user logged off | -
Mon, 22 Aug 2016 13:19:19 +0200 | 178.56.66.225 | fxsciaqulmla | - | user logged in | -
Mon, 22 Aug 2016 13:19:19 +0200 | 178.56.66.225 | fxsciaqulmla | - | user changed password | -
Mon, 22 Aug 2016 13:19:19 +0200 | 178.56.66.225 | fxsciaqulmla | - | user logged off | -
Mon, 22 Aug 2016 13:20:42 +0200 | 178.57.67.225 | faaaa0a11111 | - | user logged in | -
  • The script gives an error or what happens? It should work. – Modern1 Oct 23 '18 at 17:02

3 Answers 3

if[["$a"=1&"$b"=2&"$c"=3]];then
    #...
fi
  • thanks a lot) helped) – Lazy41 Oct 23 '18 at 17:09
  • Lazy41 then tick as solution) – Red Hot Oct 25 '18 at 12:47
  • Red Hot, thank you for your concern, but it seems to be already all day as noted by the decision. – Lazy10 Oct 25 '18 at 12:49
Examples of nested if/else in Bash:
https://www.tldp.org/LDP/abs/html/nestedifthen.html
https://stackoverflow.com/a/42906368/7436149
square brackets in bash is not a syntax of the language, it is a specific test command
that is
"[$a == $b]" is the same as"test $a == $b"

And when you write[$a == $b&$c == $d], bash parsit like"test $a == $b&&$c == $d", that is, a syntax error.
Close the parentheses, or use the test command options

1)"if[$a == $b]&[$c == $d];then"
2)"if[$a == $b -a $c == $d];then"