log report script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting log report script
# 8  
Old 08-07-2008
You can use variables, assuming you have gawk:

Code:
#!/bin/sh

dat=`date`
number="5"

/usr/bin/gawk -v num="$number" -v d="$dat" '
{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] ": " num
    }
    print ""
  }
  print d
}' file

Save this in a file, make it executable and run it as a shell script.
# 9  
Old 08-07-2008
Quote:
Originally Posted by Franklin52
You can use variables, assuming you have gawk:

Code:
#!/bin/sh

dat=`date`
number="5"

/usr/bin/gawk -v num="$number" -v d="$dat" '
{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] ": " num
    }
    print ""
  }
  print d
}' file

Save this in a file, make it executable and run it as a shell script.
I am sorry to keep asking questions ... I have put that in a script and ran. One thing is number of occurances did not print. and date was not working...i removed that part. Is there a way to print " [02/Jun/2008:10:34:36 -0600] " as an example for the corresponding uid in the same line of the input file ?

such as:

cat a.out

uid=aabbcc
Accept: 1
Reject: 1
Validate: 1
TimeStamp: [02/Jun/2008:10:34:36 -0600]

thanks much again
# 10  
Old 08-08-2008
It should work with gawk or nawk. An example if you have the timestamp in a variable:

Code:
#!/bin/sh

number="5"
ts="TimeStamp: [02/Jun/2008:10:34:36 -0600]"

/usr/bin/gawk -v num="$number" -v d="$dat" '
{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] ": " num
    }
    print ts
  }
}' file

# 11  
Old 08-08-2008
Quote:
Originally Posted by Franklin52
It should work with gawk or nawk. An example if you have the timestamp in a variable:

Code:
#!/bin/sh

number="5"
ts="TimeStamp: [02/Jun/2008:10:34:36 -0600]"

/usr/bin/gawk -v num="$number" -v d="$dat" '
{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] ": " num
    }
    print ts
  }
}' file



Hi Again,

I used nawk and got it working...I think gawk is not installed in my server. However, counts per variables like Accept, Reject did not work. I was also not bale to print the date stamp ...not sure ...tried modifying but getting the same results...any idea is appreciated. Thanks once again.
# 12  
Old 08-08-2008
CPU & Memory

Sorry, I forgot to replace the variable in the code and to add a counter:

Code:
#!/bin/sh

ts="TimeStamp: [02/Jun/2008:10:34:36 -0600]"

/usr/bin/gawk -v num="$number" -v timestamp="$ts" '
{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++){
    c++
    print "uid=" b[k]
    for(l=1;l<=i;l++){
      print a[l] ": " c
    }
    print timestamp
  }
}' file

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