shell script for log files data!

Hi Team,

please write a shell script.

It is for veritas netbackup logs. The result we currently have is a single file for each day's backups. we will keep the files in the directory and the file names are like below mentioned.

example :/opt/openv/netbackup/reports/Daily/NB_success*. The No of files are above 2000 fiels are there.

The files contains like below mentioned :

SAP_DV4_Archive 11/18/06 18:17(2)
Billing_Grv 11/07/06 01:07
SAP_E4D_Archive 11/18/06 18:38
SAP_E4D_Database none
Granv_Clients 11/07/06 03:37(8)
SAP_E6T_Database none
SAP_FID_Archive 11/18/06 18:17(2)
SAP_FID_Database none
SAP_FIP_Archive 11/18/06 18:08(2)
SAP_FIP_Database none
SAP_FIS_Archive 11/18/06 18:20(2)
SAP_FIS_Database x
SAP_O1D_Archive i
SAP_O1D_Database i
SAP_P6D_Archive 11/18/06 18:40

The first column will contain the archive name and next column will have the date and time if the bacup success otherwise it will have 'x' or 'i','none'.

please write a script and the reuslt should be as given below. if you writen a shell script with name status.sh. the script should take flags like as given below.

  1. SAP_DV4_Archive backups for the last month or year successful backups

example : status.sh -m=05 -y=06 -p=SAP_E4D_Archive

script name status.sh

-m month
-y year
-p backup policy name

You could include a "summary" option that will count up the number of input files as a baseline and report that SAP_E4D_Archive ran successfully on 26 of 31 days.

Thanks & Regards

Venkat

while read line
do
backupdate=`echo $line|awk '{print $2}'`
if [[ $backupdate = "x" || $backupdate = "i" || $backupdate = "none" ]]
then
continue
fi
backupfile=`echo $line | awk '{print $1}'`
formatstr=`echo $backupdate | awk -F"/" '{ print "status.sh -m="$1 " -y=
"$3 " -p="}'`
echo "$formatstr$backupfile"
done < tmp

Hi aju_kup

Its not working. The input files are like "NB_success*". Please dont mind its essential.

Thanks
Venkat

#! /usr/bin/ksh
for filename in NB_success*
do
while read line
do
backupdate=`echo $line|awk '{print $2}'`
if [[ $backupdate = "x" || $backupdate = "i" || $backupdate = "n
one" ]]
then
continue
fi
backupfile=`echo $line | awk '{print $1}'`
formatstr=`echo $backupdate | awk -F"/" '{ print "status.sh -m="
$1 " -y="$3 " -p="}'`
echo "$formatstr$backupfile"
done < $filename
done

Hi aju_kup,

Its taking multiple input files. but its not giveing exact output

Suppose the Input is like

Viaware_Tol_PVWXP1 06/04/06 03:35
WebMethods_wmprd 06/04/06 06:35
WebMethods_wmprd_lg 06/04/06 07:35
WebMethods_wmprd_tn 06/04/06 06:35
iXOS_Grv 06/04/06 00:15
iXOS_Grv_DS 06/04/06 00:15
iXOS_Grv_ixar 06/04/06 00:35
iXOS_Tol 06/04/06 00:15

if I run the script like

./status.sh -m=04 -y=06 -p=iXOS

the out put should like this I want.

iXOS_Grv 06/04/06 00:15
iXOS_Grv_DS 06/04/06 00:15
iXOS_Grv_ixar 06/04/06 00:35
iXOS_Tol 06/04/06 00:15

Please dont mind can you do it like this

Thanks
Venkat

Hi R Rao here is the script

################test.sh##############
###Use: ./test.sh -m 04 -y 06 -p iXOS########
##################################

while getopts m:y:p: argmnt ####please use m colon y colon p colon
do
case $argmnt in
m) aflag=1
month="$OPTARG";;
y) bflag=1
year="$OPTARG";;
p) cflag=1
filter="$OPTARG";;
*) echo "Invalid argumetn passed.."
exit 99;;
esac
done
if [[ -z $aflag ]]
then
echo "month missing..Use: -m month -y year -p filter"
exit 1
fi

if [[ -z $bflag ]]
then
echo "year missing..Use: -m month -y year -p filter"
exit 2
fi
if [[ -z $cflag ]]
then
echo "Filter missing..Use: -m month -y year -p filter"
exit 3
fi
grep -h "$filter" NB_success* | grep "$month/$year"

#! /usr/bin/ksh
mon=`echo $1 | awk -F"=" '{print $2}'`
year=`echo $2 | awk -F"=" '{print $2}'`
file=`echo $3 | awk -F"=" '{print $2}'`

for filename in tmp*.a
do awk "/$file/ && /$mon\/[0-9][0-9]\/$year/"'{ print $0 }' $filenamedone