I am new to scripting and I really could use some help. I have a log file that is constantly getting appended to every night and the output looks something like this;
05/29/03 01:54:01 nsrd: /dev/rmt/4ubn Eject operation in progress
05/29/03 01:54:10 nsrd: /dev/rmt/1ubn Mount operation in progress
05/29/03 01:54:22 nsrd: media event cleared: confirmed mount of NTBelz.033 on /dev/rmt/1ubn
05/29/03 01:54:28 nsrd: media notice: dlt7000 tape bak2.NTmfs3.065 on /dev/rmt/7ubn is full
05/29/03 01:54:29 nsrd: media notice: dlt7000 tape bak2.NTmfs3.065 used 50 GB of 35 GB capacity
05/29/03 01:54:45 nsrd: media info: loading volume bak2.NT.C.502 into /dev/rmt/4ubn
5/06/03 06:23:03 nsrd: media event cleared: confirmed mount of bak2.NTmfs4.010 on /dev/rmt/1ubn
05/06/03 06:30:08 nsrd: media notice: dlt7000 tape bak2.NTmfs3.C.062 on /dev/rmt/2ubn is full
05/06/03 06:30:08 nsrd: media notice: dlt7000 tape bak2.NTmfs3.C.062 used 49 GB of 35 GB capacity
05/06/03 06:30:24 nsrd: media info: verification of volume "bak2.NTmfs3.C.062", volid 2931725057 succeeded.
05/06/03 06:30:40 nsrd: write completion notice: Writing to volume bak2.NTmfs3.C.062 complete
05/06/03 23:58:12 nsrd: media notice: dlt7000 tape MSEXCH.376 on /dev/rmt/0ubn is full
05/06/03 23:58:12 nsrd: media notice: dlt7000 tape MSEXCH.376 used 41 GB of 35 GB capacity
05/06/03 23:59:13 nsrd: media info: verification of volume "MSEXCH.376", volid 2818370561 succeeded.
05/06/03 23:59:27 nsrd: write completion notice: Writing to volume MSEXCH.376 complete
I need the script to read this log file and find any line that contains "is full" and has today's date. Once I have those lines I need to get $8 (eg: bak2.NTmfs3.C.062, MSEXCH.376, bak2.NTmfs3.065) field and only save the field name that contains "NTmfs3" with no "C". So from this example I want the field "bak2.NTmfs2.065" to be saved into a filename for later use and I need this file appended with any other field it finds that meets the criteria.
Here's what I got so far. I figure I need to put it in a while loop because this log is constantly being written to and I need to catch the "is full" lines as they come in. The problem with what I've written is that when I get the value for $NAME(ie; NTmfs4) I want to print the full field (bak2.NTmfs4.060) and save it to a file. That is just not working out.
#!/bin/sh -x
LOGDIR=/nsr/logs/daemon.log
TODAY=`date +%m/%d/%y`
TAPEDIR=/var/tmp/extreme_cloning
RUN=true
while [ $RUN ]
do
Volume=`tail -1 $LOGDIR | grep "is full$" | awk '{print $8}'`
NAME=`tail -1 $LOGDIR |grep "is full$" | awk '{print $8}' | cut -d "." -f2 | awk '{print $1}'`
LINE=`tail -1 $LOGDIR | grep "is full$" | awk '{print $8}' | awk 'BEGIN {FS="."} {print NF}'`
if [ "$LINE" = "3" ] && [ "$NAME" = "NTmfs4" ]; then
#echo the Volume name containing the $NAME and append to $TAPEDIR/tapes
else
echo "Finish"
exit
fi
done
Any help is greatly appreciated.
05/29/03 01:54:01 nsrd: /dev/rmt/4ubn Eject operation in progress
05/29/03 01:54:10 nsrd: /dev/rmt/1ubn Mount operation in progress
05/29/03 01:54:22 nsrd: media event cleared: confirmed mount of NTBelz.033 on /dev/rmt/1ubn
05/29/03 01:54:28 nsrd: media notice: dlt7000 tape bak2.NTmfs3.065 on /dev/rmt/7ubn is full
05/29/03 01:54:29 nsrd: media notice: dlt7000 tape bak2.NTmfs3.065 used 50 GB of 35 GB capacity
05/29/03 01:54:45 nsrd: media info: loading volume bak2.NT.C.502 into /dev/rmt/4ubn
5/06/03 06:23:03 nsrd: media event cleared: confirmed mount of bak2.NTmfs4.010 on /dev/rmt/1ubn
05/06/03 06:30:08 nsrd: media notice: dlt7000 tape bak2.NTmfs3.C.062 on /dev/rmt/2ubn is full
05/06/03 06:30:08 nsrd: media notice: dlt7000 tape bak2.NTmfs3.C.062 used 49 GB of 35 GB capacity
05/06/03 06:30:24 nsrd: media info: verification of volume "bak2.NTmfs3.C.062", volid 2931725057 succeeded.
05/06/03 06:30:40 nsrd: write completion notice: Writing to volume bak2.NTmfs3.C.062 complete
05/06/03 23:58:12 nsrd: media notice: dlt7000 tape MSEXCH.376 on /dev/rmt/0ubn is full
05/06/03 23:58:12 nsrd: media notice: dlt7000 tape MSEXCH.376 used 41 GB of 35 GB capacity
05/06/03 23:59:13 nsrd: media info: verification of volume "MSEXCH.376", volid 2818370561 succeeded.
05/06/03 23:59:27 nsrd: write completion notice: Writing to volume MSEXCH.376 complete
I need the script to read this log file and find any line that contains "is full" and has today's date. Once I have those lines I need to get $8 (eg: bak2.NTmfs3.C.062, MSEXCH.376, bak2.NTmfs3.065) field and only save the field name that contains "NTmfs3" with no "C". So from this example I want the field "bak2.NTmfs2.065" to be saved into a filename for later use and I need this file appended with any other field it finds that meets the criteria.
Here's what I got so far. I figure I need to put it in a while loop because this log is constantly being written to and I need to catch the "is full" lines as they come in. The problem with what I've written is that when I get the value for $NAME(ie; NTmfs4) I want to print the full field (bak2.NTmfs4.060) and save it to a file. That is just not working out.
#!/bin/sh -x
LOGDIR=/nsr/logs/daemon.log
TODAY=`date +%m/%d/%y`
TAPEDIR=/var/tmp/extreme_cloning
RUN=true
while [ $RUN ]
do
Volume=`tail -1 $LOGDIR | grep "is full$" | awk '{print $8}'`
NAME=`tail -1 $LOGDIR |grep "is full$" | awk '{print $8}' | cut -d "." -f2 | awk '{print $1}'`
LINE=`tail -1 $LOGDIR | grep "is full$" | awk '{print $8}' | awk 'BEGIN {FS="."} {print NF}'`
if [ "$LINE" = "3" ] && [ "$NAME" = "NTmfs4" ]; then
#echo the Volume name containing the $NAME and append to $TAPEDIR/tapes
else
echo "Finish"
exit
fi
done
Any help is greatly appreciated.