Skip to content
Advertisement

Generate a report using awk

I have /etc/fstab entries on 100 servers and i’m trying to write a awk script to identify following.

sup01p.abc.com.au | SUCCESS | rc=0 >>

10.15.23.25:/tools /data/store        nfs     defaults,nodev  0       0
10.15.23.25:/kdump01 /data/kdump     nfs     defaults,nodev  0       0
10.15.23.25:/ops        /data/ops  nfs     defaults,nodev  0       0

What i need is, first my awk script need to print the domain name, then it should print

10.15.23.25:/tools  /data/store - this is an invalid entry, 

tools incorrectly mounted on store and is not valid, but kdump01 mounted correctly on kdump , ops mounted correctly on ops)

How can i print a report like this using awk or sed ? (print only invalid nfs mounts)

output should be like this

sup01p.abc.com.au 
10.15.23.25:/tools /data/store

I managed to add the follwing script and it lists servername and mount points

cat check |  awk '$1~/com.au/{ print $1 ;next} /10.15.23.25/{print $1;}/data/{print $2;print "======"}'

sup01p.abc.com.au
10.15.23.25:/tools
/data/store
======
10.15.23.25:/kdump01
/data/kdump
=====
10.15.23.25:/ops
/data/ops
======

Advertisement

Answer

awk solution (for your current input):

cat check | awk 'NR==1{ print $1; next }{ m=substr($1,index($1,"/")+1); 
            sub(/[^a-z]+/,"",m); if($2!~m) print $1,$2 }' 

The output:

sup01p.abc.com.au
10.15.23.25:/tools /data/store
Advertisement