log report script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting log report script
# 1  
Old 08-07-2008
log report script

Hello everyone,

By any chance, anyone has a script (shell) that I can modify for the following:

I have daily log files and they look like:

Accept aabbcc [02/Jun/2008:10:34:36 -0600] "111.11.111.111 uid=MyID, ou=People, o=helloworld.com" "webagent" [] []
Reject aabbcc [02/Jun/2008:10:34:36 -0600] "111.11.111.111 uid=MyID, ou=People, o=helloworld.com" "webagent" [] []
Validate ddeeff [02/Jun/2008:10:34:36 -0600] "111.11.111.111 uid=MyID, ou=People, o=helloworld.com" "webagent" [] []


The need is to run a script against it with some inputs, such as:

./script.sh uid start_date end_date all_dates

above may not contain the end_date; but eventually there should be sometimes.

The output should be something like this:

# Total Activities based on uid

uid=aabbcc
Accept: #
Reject: #
Validate: #

uid=ddeeff
Accept: #
Reject: #
Validate: #


so on... If anyone can help, greatly appreciated.
# 2  
Old 08-07-2008
If you get errors use nawk, gawk or /usr/xpg4/bin/awk on Solaris.

Code:
awk '
!($1 in a){a[++i]=$1;a[$1]}
!($2 in b){b[++j]=$2;b[$2]}
END{
  for(k=1;k<=j;k++){
    print "uid=" b[k]
    for(l=1;l<=i;l++){
      print a[l] ": #"
    }
    print ""
  }
}' file

Regards
# 3  
Old 08-07-2008
Quote:
Originally Posted by Franklin52
If you get errors use nawk, gawk or /usr/xpg4/bin/awk on Solaris.

Code:
awk '
!($1 in a){a[++i]=$1;a[$1]}
!($2 in b){b[++j]=$2;b[$2]}
END{
  for(k=1;k<=j;k++){
    print "uid=" b[k]
    for(l=1;l<=i;l++){
      print a[l] ": #"
    }
    print ""
  }
}' file

Regards


I appreciate for the response. I tried as you suggested on solaris but getting the error:
i used it as

awk -f a.awk a.txt > a.out

awk: syntax error near line 1
awk: bailing out near line 1

any suggestion please?

thnx much again
# 4  
Old 08-07-2008
As mentioned, on Solaris:

Code:
/usr/xpg4/bin/awk '
!($1 in a){a[++i]=$1;a[$1]}
!($2 in b){b[++j]=$2;b[$2]}
END{
  for(k=1;k<=j;k++){
    print "uid=" b[k]
    for(l=1;l<=i;l++){
      print a[l] ": #"
    }
    print ""
  }
}' file

Regards
# 5  
Old 08-07-2008
Quote:
Originally Posted by Franklin52
As mentioned, on Solaris:

Code:
/usr/xpg4/bin/awk '
!($1 in a){a[++i]=$1;a[$1]}
!($2 in b){b[++j]=$2;b[$2]}
END{
  for(k=1;k<=j;k++){
    print "uid=" b[k]
    for(l=1;l<=i;l++){
      print a[l] ": #"
    }
    print ""
  }
}' file

Regards

I appreciate for very fast response; I had tried the same as code above but it was the same error...I am unsure why it is bailing out at the 1st line...and syntax error..

awk: syntax error near line 1
awk: bailing out near line 1
# 6  
Old 08-07-2008
It works well with the newer versions of awk, I made some changes, give this a try:

Code:
/usr/xpg4/bin/awk '
{if(!($1 in a)){a[++i]=$1;a[$1]}}
{if(!($2 in b)){b[++j]=$2;b[$2]}}
END{
  for(k=1;k<=j;k++){
    print "uid=" b[k]
    for(l=1;l<=i;l++){
      print a[l] ": #"
    }
    print ""
  }
}' file

# 7  
Old 08-07-2008
Quote:
Originally Posted by Franklin52
It works well with the newer versions of awk, I made some changes, give this a try:

Code:
/usr/xpg4/bin/awk '
{if(!($1 in a)){a[++i]=$1;a[$1]}}
{if(!($2 in b)){b[++j]=$2;b[$2]}}
END{
  for(k=1;k<=j;k++){
    print "uid=" b[k]
    for(l=1;l<=i;l++){
      print a[l] ": #"
    }
    print ""
  }
}' file


Hi again, I added the following it works partially what I was looking for:

#!/usr/bin/awk -f
#!/usr/bin/nawk -f
#!/usr/bin/mawk -f
#!/usr/bin/gawk -f

output was:

uid=aabbcc
Accept: #
Reject: #
Validate: #


Is there a way to replace # with number of occurance and is there also a way to print the date stamp in the file below it ?

thanks much once again
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Report generation using script

Hi all I have a unix script that generates a report with the following information: uptime, mounted file systems, disk usage (> 90% --> critical, <75%-90%> --> warning, < 75% healthy), Mem usage, CPU usage and load average. But I would like to create one single report containing all this... (5 Replies)
Discussion started by: fretagi
5 Replies

2. Shell Programming and Scripting

Outputting data from log file to report

I have a log file that looks like this. the lines are grouped. 2 lines per entry. M: 2019-01-25 13:02:31.698 P25, received network transmission from KI4EKI to TG 10282 M: 2019-01-25 13:02:35.694 P25, network end of transmission, 4.3 seconds, 1% packet loss M: 2019-01-25 13:02:38.893 P25,... (7 Replies)
Discussion started by: ae4ml
7 Replies

3. Shell Programming and Scripting

Parsing a log file and creating a report script

The log file is huge and lot of information, i would like to parse and make a report . below is the log file looks like: REPORT DATE: Mon Aug 10 04:16:17 CDT 2017 SYSTEN VER: v1.3.0.9 TERMINAL TYPE: prod SYSTEM: nb11cu51 UPTIME: 04:16AM up 182 days 57 mins min MODEL, TYPE, and SN:... (8 Replies)
Discussion started by: amir07
8 Replies

4. Shell Programming and Scripting

Need to develop a bash script to create customized report from the server log

Hi, I need to develop a bash script to create customized report from the server log (red hat 5.8 64 bit Operating system). The following is one of the log for our internal application task. <2015.03.03 20:09:52 274 +0800><I><DSCTH01><http-0.0.0.0-443-2><security> GUI request succeeded for... (1 Reply)
Discussion started by: pugazhendhi_r
1 Replies

5. Shell Programming and Scripting

Report from Log file using awk

Hi Gurus, I've log files like below: extint.performance.log.2014-04-10-00-00-00.13 extint.performance.log.2014-04-11-00-00-00.12 extint.performance.log.2014-04-12-00-00-00.12 extint.performance.log.2014-04-12-14-35-11.11 extint.performance.log.2014-04-13-00-00-00.10... (4 Replies)
Discussion started by: VasuKukkapalli
4 Replies

6. Shell Programming and Scripting

Read Log Realtime and Parse out Information for a Report

I'm not too fluent at this and having problems comprehending / coming up with a way to do it. Our telephone system is spitting out call information on it's maintenance (serial) port which i have connected to a linux box. I want to be able to monitor the output of this text and when a 911 call is... (1 Reply)
Discussion started by: Pythong
1 Replies

7. Shell Programming and Scripting

Assistance on making a report log file

:):):):):) (0 Replies)
Discussion started by: bryan101
0 Replies

8. Homework & Coursework Questions

shell script that can create, monitor the log files and report the issues for matching pattern

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write an automated shell program(s) that can create, monitor the log files and report the issues for matching... (0 Replies)
Discussion started by: itian2010
0 Replies

9. Shell Programming and Scripting

Check for files and log report if missing

Hi, I need a shell program that will prompt the user to input a dept name to the script. The script should then check a specific directory called ‘report' in the home directory of each member of that dept. If the report directory does not exist, or there are no contents in the directory,... (2 Replies)
Discussion started by: johnnyvlme
2 Replies

10. Shell Programming and Scripting

Help generate report from log files

Hi Expert, I have some confusing to generate report from the log file as shown below: filename :test1.log start_time date end_time number code P 000029.621 20070823 000029 12134567890 111111111111 00 0 000 003... (4 Replies)
Discussion started by: bucci
4 Replies
Login or Register to Ask a Question