1826159 Members
4593 Online
109691 Solutions
New Discussion

script using awk

 
SOLVED
Go to solution
kholikt
Super Advisor

script using awk

Hi,

I have a cronjob that run the omnimm command to scan all the media in a our autoloader automatcially.

This is how the output will be generated.

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 09:58:39
STARTING Media Agent "DDS_1"

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 09:58:40
Loading medium from slot 1 to device /dev/rmt/0m

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 09:59:19
Unloading medium to slot 1 from device /dev/rmt/0m

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 09:59:40
Loading medium from slot 2 to device /dev/rmt/0m

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 10:00:24
Unloading medium to slot 2 from device /dev/rmt/0m

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 10:00:45
Loading medium from slot 3 to device /dev/rmt/0m

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 10:01:27
Unloading medium to slot 3 from device /dev/rmt/0m

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 10:01:49
Loading medium from slot 4 to device /dev/rmt/0m

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 10:02:35
Unloading medium to slot 4 from device /dev/rmt/0m

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 10:02:56
Loading medium from slot 5 to device /dev/rmt/0m

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 10:03:39
Unloading medium to slot 5 from device /dev/rmt/0m

[Warning] From: MSM@myserver "DDS_1" Time: 09/27/02 10:04:01
[65:93] Slot 6 configured as cleaning slot ==> skipped.

[Normal] From: MMA@myserver "DDS_1" Time: 09/27/02 10:04:01
COMPLETED Media Agent "DDS_1"

[Normal] From: MSM@myserver "DDS_1" Time: 09/27/02 10:04:01

Slot [side] Medium type Medium Label (ID)
===============================================================================
1 OmniBack II ESC_TRD_ARC_FRI
2 OmniBack II ESC_TBD_ARC_FRI
3 OmniBack II ESC_TRA_ARC_FRI
4 cpio
5 tar
6 Cleaning tape
Final report: 5 media out of 5 successfully scanned.

I only want the following portion.

Slot [side] Medium type Medium Label (ID)
===============================================================================
1 OmniBack II ESC_TRD_ARC_FRI
2 OmniBack II ESC_TBD_ARC_FRI
3 OmniBack II ESC_TRA_ARC_FRI
4 cpio
5 tar
6 Cleaning tape
Final report: 5 media out of 5 successfully scanned.

Although I know that I can use the tail to extract the last ten lines but it doesn't seem to be very robust.

How could I find the pattern "Slot [side]" and print the next 6 lines?
abc
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: script using awk

Hi:

# sed -n '/^Slot/,/^Final/p' filename

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: script using awk

Hi (again):

Oh, you wanted 'awk'. In that case:

# awk '/^Slot/,/^Final/ {print $0}' filename

Regards!

...JRF...
kholikt
Super Advisor

Re: script using awk

Thanks so much.

Just wondering I have two single slot tape drive

[Normal] From: MSM@server1 "DDS_1_server1" Time: 09/27/02 10:53:57
OmniBack II medium "ESC_TBP_ARC_FRI" found.

[Normal] From: MMA@server1 "DDS_1_server1" Time: 09/27/02 10:52:48
/dev/rmt/0m
Medium verification completed, 0 errors found

[Normal] From: MMA@server1 "DDS_1_server1" Time: 09/27/02 10:52:48
COMPLETED Media Agent "DDS_1_server1"

Final report: 1 media out of 1 successfully scanned.
[Normal] From: MMA@server1 "DDS_2_tpsbwp" Time: 09/27/02 10:52:49
STARTING Media Agent "DDS_2_server1"

[Normal] From: MSM@server1 "DDS_2_server1" Time: 09/27/02 10:53:58
OmniBack II medium "ESC_PBP_ARC_FRI" found.

[Normal] From: MMA@server1 "DDS_2_server1" Time: 09/27/02 10:52:49
/dev/rmt/3m
Medium verification completed, 0 errors found

Is that possible to also extract the output as

DDS_1_server1

OmniBack II medium "ESC_TBP_ARC_FRI" found.
Medium verification completed, 0 errors found

DDS_2_server2
OmniBack II medium "ESC_PBP_ARC_FRI" found.
Medium verification completed, 0 errors found
abc
kholikt
Super Advisor

Re: script using awk

I know I can do something like this "awk '/^ OmniBack II/{print $0}'"

but I won't be to capture the "Medium verification completed, 0 errors found" message
abc
Robin Wakefield
Honored Contributor

Re: script using awk

Hi,

Something like:

awk '/From/{drive=$4}
/OmniBack/{gsub("\"","",drive);print drive;print}
/verification/{print;print ""}' filename

should do it.

Rgds, Robin