1+ #! /bin/bash
2+
3+ export FILE_NAME=trace.log
4+
5+ # ## Write the example file which we will use
6+ cat << EOF > $FILE_NAME
7+ 03/22 08:51:01 INFO :.main: *************** RSVP Agent started ***************
8+ 03/22 08:51:01 INFO :...locate_configFile: Specified configuration file: /u/user10/rsvpd1.conf
9+ 03/22 08:51:01 INFO :.main: Using log level 511
10+ 03/22 08:51:01 INFO :..settcpimage: Get TCP images rc - EDC8112I Operation not supported on socket.
11+ 03/22 08:51:01 INFO :..settcpimage: Associate with TCP/IP image name = TCPCS
12+ 03/22 08:51:02 INFO :..reg_process: registering process with the system
13+ 03/22 08:51:02 INFO :..reg_process: attempt OS/390 registration
14+ 03/22 08:51:02 INFO :..reg_process: return from registration rc=0
15+ 03/22 08:51:03 TRACE :...read_physical_netif: Home list entries returned = 7
16+ 03/22 08:51:03 INFO :...read_physical_netif: index #0, interface VLINK1 has address 129.1.1.1, ifidx 0
17+ 03/22 08:51:03 INFO :...read_physical_netif: index #1, interface TR1 has address 9.37.65.139, ifidx 1
18+ 03/22 08:51:03 INFO :...read_physical_netif: index #2, interface LINK11 has address 9.67.100.1, ifidx 2
19+ 03/22 08:51:03 INFO :...read_physical_netif: index #3, interface LINK12 has address 9.67.101.1, ifidx 3
20+ 03/22 08:51:03 INFO :...read_physical_netif: index #4, interface CTCD0 has address 9.67.116.98, ifidx 4
21+ 03/22 08:51:03 INFO :...read_physical_netif: index #5, interface CTCD2 has address 9.67.117.98, ifidx 5
22+ 03/22 08:51:04 INFO :...read_physical_netif: index #6, interface LOOPBACK has address 127.0.0.1, ifidx 0
23+ 03/22 08:51:04 INFO :....mailslot_create: creating mailslot for timer
24+ 03/22 08:51:04 INFO :...mailbox_register: mailbox allocated for timer
25+ 03/22 08:51:04 INFO :.....mailslot_create: creating mailslot for RSVP
26+ 03/22 08:51:04 INFO :....mailbox_register: mailbox allocated for rsvp
27+ 03/22 08:51:06 INFO :.....mailslot_create: creating mailslot for RSVP via UDP
28+ 03/22 08:51:06 WARNING :.....mailslot_create: setsockopt(MCAST_ADD) failed - EDC8116I Address not available.
29+ 03/22 08:51:05 INFO :....mailbox_register: mailbox allocated for rsvp-udp
30+ 03/22 08:51:05 TRACE :..entity_initialize: interface 129.1.1.1, entity for rsvp allocated and initialized
31+ 03/22 08:51:05 INFO :.....mailslot_create: creating mailslot for RSVP
32+ 03/22 08:51:05 INFO :....mailbox_register: mailbox allocated for rsvp
33+ 03/22 08:51:05 INFO :.....mailslot_create: creating mailslot for RSVP via UDP
34+ 03/22 08:51:05 WARNING :.....mailslot_create: setsockopt(MCAST_ADD) failed - EDC8116I Address not available.
35+ 03/22 08:51:05 INFO :....mailbox_register: mailbox allocated for rsvp-udp
36+ 03/22 08:51:05 TRACE :..entity_initialize: interface 9.37.65.139, entity for rsvp allocated and initialized
37+ 03/22 08:51:05 INFO :.....mailslot_create: creating mailslot for RSVP
38+ 03/22 08:51:06 INFO :....mailbox_register: mailbox allocated for rsvp
39+ 03/22 08:51:06 INFO :.....mailslot_create: creating mailslot for RSVP via UDP
40+ 03/22 08:51:06 WARNING :.....mailslot_create: setsockopt(MCAST_ADD) failed - EDC8116I Address not available.
41+ 03/22 08:51:06 INFO :....mailbox_register: mailbox allocated for rsvp-udp
42+ 03/22 08:51:06 TRACE :..entity_initialize: interface 9.67.100.1, entity for rsvp allocated and initialized
43+ 03/22 08:51:06 INFO :.....mailslot_create: creating mailslot for RSVP
44+ 03/22 08:51:06 INFO :....mailbox_register: mailbox allocated for rsvp
45+ 03/22 08:51:06 INFO :.....mailslot_create: creating mailslot for RSVP via UDP
46+ 03/22 08:51:07 WARNING :.....mailslot_create: setsockopt(MCAST_ADD) failed - EDC8116I Address not available.
47+ 03/22 08:51:07 INFO :....mailbox_register: mailbox allocated for rsvp-udp
48+ 03/22 08:51:07 TRACE :..entity_initialize: interface 9.67.101.1, entity for rsvp allocated and initialized
49+ 03/22 08:51:07 INFO :.....mailslot_create: creating mailslot for RSVP
50+ 03/22 08:51:07 INFO :....mailbox_register: mailbox allocated for rsvp
51+ 03/22 08:51:07 INFO :.....mailslot_create: creating mailslot for RSVP via UDP
52+ 03/22 08:51:08 INFO :....mailbox_register: mailbox allocated for rsvp-udp
53+ 03/22 08:51:08 TRACE :..entity_initialize: interface 9.67.116.98, entity for rsvp allocated and initialized
54+ 03/22 08:51:08 INFO :.....mailslot_create: creating mailslot for RSVP
55+ 03/22 08:51:08 INFO :....mailbox_register: mailbox allocated for rsvp
56+ 03/22 08:51:08 INFO :.....mailslot_create: creating mailslot for RSVP via UDP
57+ 03/22 08:51:08 INFO :....mailbox_register: mailbox allocated for rsvp-udp
58+ 03/22 08:51:08 TRACE :..entity_initialize: interface 9.67.117.98, entity for rsvp allocated and initialized
59+ EOF
60+
61+
62+ # ### Cut examples:
63+
64+ # Extract only the 2nd & 3rd column (field) of each line time
65+ cut -d " " -f 2,3 $FILE_NAME
66+
67+ # Extract only the log trace levels and remove duplications
68+ cut -d " " -f 3 $FILE_NAME | sort | uniq
69+
70+ # Count the number of each log type
71+ # INFO = 41
72+ # TRACE = 7
73+ # WARNING = 4
74+
75+ # Simple solution:
76+ echo -e INFO = $( cut -d ' ' -f 3 $FILE_NAME | grep INFO | wc -l)
77+ echo -e TRACE = $( cut -d ' ' -f 3 $FILE_NAME | grep TRACE | wc -l)
78+ echo -e WARNING = $( cut -d ' ' -f 3 $FILE_NAME | grep WARNING | wc -l)
79+
80+ # ##
81+ # ## Advanced solution using dynamic for loop:
82+ # ##
83+
84+ # ## Extract the log levels
85+ LOG_LEVEL=$( cut -d " " -f 3 $FILE_NAME | sort | uniq)
86+
87+ # ## Loop over each log level and count entries
88+ for LEVEL in $LOG_LEVEL
89+ do
90+ echo -e $LEVEL = $( cut -d ' ' -f 3 $FILE_NAME | grep $LEVEL | wc -l)
91+ done
92+
93+
94+ # ## Extract IP addresses
95+ grep -oE " \b([0-9]{1,3}\.){3}[0-9]{1,3}\b" $FILE_NAME | sort | uniq
0 commit comments