Pages

Thursday, September 17, 2015

How to get user details from weblogic access logs ?



Below shell script to get all logged in user , log in & log out time . You have to pass access.log as parameter


---------------------------------------------------------------------------------------------------------------------
if [ $# != 1 ]

then

echo "Usage : ./user.sh <access.log>"

exit 0

fi


file=$1

now=`date  +%s`

touch  /tmp/inactive /tmp/active


#### function to calculate the time out

timeout (){

   dt1=`echo $1 | sed 's:/:-:g; s/:/ /'`

              t1=`date --date="$dt1" +%s`

                let "tDiff=$now-$t1"
                let "hDiff=$tDiff/3600"
                

                if [ $hDiff -lt 1 ]
                  then
                     echo " $2 and last activity at `echo $lastact` " >> /tmp/active
                  else
                     echo " $2 and last activity at `echo $lastact`  " >> /tmp/inactive
                fi


         }




echo "unique  users logged in so far "

grep "adfAuthentication?login=true" $file | awk '{print $3}' |  sort -u  > /tmp/user.txt

more +2 /tmp/user.txt

echo "number of unique users loged in so far is   ` more +2 /tmp/user.txt | wc -l ` "

echo "##########################"

echo "users logged out so far "

grep "adfAuthentication?logout=true" $file | awk '{print $3}' |  sort -u  > /tmp/log_out.txt

more  /tmp/log_out.txt

echo "number of users  loged  out so far is   ` more /tmp/log_out.txt | wc -l ` "



more +2 /tmp/user.txt | while read LINE
  do

    login=`grep $LINE $file | grep "adfAuthentication?login=true" |  awk '{print $4}' | cut -f2 -d"[" `

    logout=`grep $LINE $file | grep "adfAuthentication?logout=true" | awk  '{print $4}' | cut -f2 -d"[" `



        if [ $logout ]

          then
             
              a=`echo $login | wc -w`
              b=`echo $logout | wc -w`
             
                 if [ $a -eq $b ]
                
                    then
                      
                        echo " $LINE login at `echo $login`  logout at  `echo $logout` " >> /tmp/inactive
                    
                    else

                        lastlogin=`echo $login | awk  '{print $NF}'`
                        lastout=`echo $logout| awk  '{print $NF}'`
                    
                        dli=`echo $lastlogin | sed 's:/:-:g; s/:/ /'`
                        tli=`date --date="$dli" +%s`

                        dlo=`echo $lastout | sed 's:/:-:g; s/:/ /'`
                        tlo=`date --date="$dlo" +%s`
                       
                              if [ $tlo -gt $tli ]

                                then
                           
                                   echo " $LINE logins at `echo $login `  logout at  `echo $logout` "  >> /tmp/inactive
                                else
                     
                                   lastact=`grep $LINE $file | tail -1 |  awk  '{print $4}' | cut -f2 -d"["`
                                   session="$LINE logins at `echo $login`  logout at  `echo $logout` "
                                   timeout "$lastact" "$session"

                              fi


                  fi

         else 
             
           session="$LINE login at `echo $login`"
           lastact=`grep $LINE $file | tail -1 |  awk  '{print $4}' | cut -f2 -d"["`
           timeout "$lastact"  "$session"
         fi


  done


echo "###############"
echo "Active Session "
more /tmp/active
echo "###############"
echo "Inactive Session "
more /tmp/inactive
echo "###############"
rm  /tmp/inactive /tmp/active

------------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment