leylakhavanin
asked on
ksh: How to merge several files into one file and customize layout of the merged file?
Hello all,
I have a directory called /apps/logs/sct/{$YEAR}/{$M ONTH}. I have the following ksh script which check for year and month directory and create them if they don't exist.
#!/bin/ksh
YEAR=`date '+%Y'`
MONTH=`date '+%y-%B'`
DAY=`date '+%d'`
BASE_DIR=/apps/logs/sct
cd ${BASE_DIR}
if [ -e ${YEAR} ]
then
if [ ! -e ${MONTH} ]
then
mkdir ${YEAR}/${MONTH}
fi
else
mkdir -p ${YEAR}/${MONTH}
fi
/apps/logs/sct/2005/05-Jul y contains several files with the following reports:
Subject: run_cron monthly on ecs51h2
==== START run_cron monthly on ecs51h2 === Fri Jul 1 05:05:00 EDT 2005
Summary File /var/sct/logs/monthly.ecs5 1h2.200507 01.sum.01
For details refer to Log File:
/var/sct/logs/monthly.ecs5 1h2.200507 01.log.01
audit_filesys Warning : 1 files are owned by root and world-writable
audit_filesys Warning : 1 directories are world-writable and not sticky
audit_filesys Warning : 5581 files are not owned by a recognized owner or group
audit_filesys Warning : 2 suspected extra password and group files
pwck Warning : 6 Password file inconsistencies
verifypw ERROR : 3 Password entries are not coinciding with SILAS.
List_of_SGID_and_SUID_Prog rams Display : 1 List of SUID Programs
=== END run_cron monthly on ecs51h2 === Fri Jul 1 05:06:33 EDT 2005
=== 1 Error(s) and 5 Warning(s) ===
Subject: run_cron monthly on nicdev2
==== START run_cron monthly on nicdev2 === Fri Jul 1 12:43:17 EDT 2005
Summary File /var/sct/logs/monthly.nicd ev2.200507 01.sum.01
For details refer to Log File:
/var/sct/logs/monthly.nicd ev2.200507 01.log.01
audit_filesys Warning : 1 files are owned by root and world-writable
audit_filesys Warning : 7 directories are world-writable and not sticky
audit_filesys Warning : 97 files are not owned by a recognized owner or group
audit_filesys Warning : 3 suspected extra password and group files
pwck Warning : 17 Password file inconsistencies
su_chk Warning : 3 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog rams Display : 2 List of SGID Programs
List_of_SGID_and_SUID_Prog rams Display : 4 List of SUID Programs
=== END run_cron monthly on nicdev2 === Fri Jul 1 12:45:12 EDT 2005
=== 0 Error(s) and 6 Warning(s) ===
Now, I want to merge these two files (ecs51h2,nicdev2) into one file and create one report. I also was wondering whether there is any way I can make changes to the format of each files before it's sent to the merged file. As you see each file has a subject which I want to add some border around each one by using +. In a simple way, I want to format the merge file some how that can be easy to read.
Please be clear with details when you are commenting on my question.
Thanks in advance
Leyla
I have a directory called /apps/logs/sct/{$YEAR}/{$M
#!/bin/ksh
YEAR=`date '+%Y'`
MONTH=`date '+%y-%B'`
DAY=`date '+%d'`
BASE_DIR=/apps/logs/sct
cd ${BASE_DIR}
if [ -e ${YEAR} ]
then
if [ ! -e ${MONTH} ]
then
mkdir ${YEAR}/${MONTH}
fi
else
mkdir -p ${YEAR}/${MONTH}
fi
/apps/logs/sct/2005/05-Jul
Subject: run_cron monthly on ecs51h2
==== START run_cron monthly on ecs51h2 === Fri Jul 1 05:05:00 EDT 2005
Summary File /var/sct/logs/monthly.ecs5
For details refer to Log File:
/var/sct/logs/monthly.ecs5
audit_filesys Warning : 1 files are owned by root and world-writable
audit_filesys Warning : 1 directories are world-writable and not sticky
audit_filesys Warning : 5581 files are not owned by a recognized owner or group
audit_filesys Warning : 2 suspected extra password and group files
pwck Warning : 6 Password file inconsistencies
verifypw ERROR : 3 Password entries are not coinciding with SILAS.
List_of_SGID_and_SUID_Prog
=== END run_cron monthly on ecs51h2 === Fri Jul 1 05:06:33 EDT 2005
=== 1 Error(s) and 5 Warning(s) ===
Subject: run_cron monthly on nicdev2
==== START run_cron monthly on nicdev2 === Fri Jul 1 12:43:17 EDT 2005
Summary File /var/sct/logs/monthly.nicd
For details refer to Log File:
/var/sct/logs/monthly.nicd
audit_filesys Warning : 1 files are owned by root and world-writable
audit_filesys Warning : 7 directories are world-writable and not sticky
audit_filesys Warning : 97 files are not owned by a recognized owner or group
audit_filesys Warning : 3 suspected extra password and group files
pwck Warning : 17 Password file inconsistencies
su_chk Warning : 3 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog
List_of_SGID_and_SUID_Prog
=== END run_cron monthly on nicdev2 === Fri Jul 1 12:45:12 EDT 2005
=== 0 Error(s) and 6 Warning(s) ===
Now, I want to merge these two files (ecs51h2,nicdev2) into one file and create one report. I also was wondering whether there is any way I can make changes to the format of each files before it's sent to the merged file. As you see each file has a subject which I want to add some border around each one by using +. In a simple way, I want to format the merge file some how that can be easy to read.
Please be clear with details when you are commenting on my question.
Thanks in advance
Leyla
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tintin,
I haven't able to run this yet due to some permission error so I have to go and find out why I am getting this error. In the mean time, would you explain to me why you are using " rm -f combined.report " and " rm -f $file " in the for loop wouldn't those remove the file?
I haven't able to run this yet due to some permission error so I have to go and find out why I am getting this error. In the mean time, would you explain to me why you are using " rm -f combined.report " and " rm -f $file " in the for loop wouldn't those remove the file?
ASKER
ahoffmann,
Thanks for your comment, but I do not want to merge only two file. I just gave an example of two of the 70 files that needs to be merged. I also do not know how to work with awk, perl, sed, tr
>easy to read by what/whom? humans, machines?what is the definition of "easy"?
By humans. Since the combined report contains Heather, Subject,ERROR and Warning for 70 different server one after another I just want to make it easier to whomever wants to read it. In a better way, an easy way to make it distinguishable between each server names and their report.
Hope that made it clear.
Thanks for your comment, but I do not want to merge only two file. I just gave an example of two of the 70 files that needs to be merged. I also do not know how to work with awk, perl, sed, tr
>easy to read by what/whom? humans, machines?what is the definition of "easy"?
By humans. Since the combined report contains Heather, Subject,ERROR and Warning for 70 different server one after another I just want to make it easier to whomever wants to read it. In a better way, an easy way to make it distinguishable between each server names and their report.
Hope that made it clear.
> .. but I do not want to merge only two file. I just gave an example of two of the 70 files
and what is the problem using my method to merge 70 files?
awk '($1=="Subject:"){print "+++++++++++++++++++";prin t;print "+++++++++++++++++++"} file-containing-subject >> merged-file
and what is the problem using my method to merge 70 files?
awk '($1=="Subject:"){print "+++++++++++++++++++";prin
ASKER
Ahoffmann,
I never said that ther eis some thing wrong with your method. As I mentioned before I don't know how do awk and I guess that's where the confusion came from. The following is what I am running now:
#!/bin/ksh
YEAR= `date '+%Y'`
MONTH=`date '+%y-%B'`
DAY=`date '+%d'`
BASE_DIR=/apps/logs/sct
#Check to make sure the Year and Month direcotries exist if not
#create the cureent year/month directory
cd ${BASE_DIR}
if [ -d ${YEAR} ]
then
if [ ! -e ${MONTH} ]
then
mkdir ${YEAR}/${MONTH}
fi
else
mkdir -p ${YEAR}/${MONTH}
fi
#Now move the files into the directory.
cp *.---.---.com /apps/logs/sct/${YEAR}/${M ONTH}
#Combined all the file into one file called mergedfile
cat ecs45h1 >mergedfile
cat ecs49n >>mergedfile
awk '($1=="Subject:")'{print "+++++++++++++++++++";prin t;print "+++++++++++++++++++"} file-containing-subject >> merged-file
These are the error that I am getting?!?!?!?!? Any reason why?
mkdir: Failed to make directory "/05-July"; File exists
cp: /apps/logs/sct//05-July not found
cat: cannot open ecs45h1
cat: cannot open ecs49n
awk: syntax error near line 1
awk: illegal statement near line 1
Tintin,
when I used these line of code, it worked fine
#Change the directory and create a combined report
cd /apps/logs/sct/${YEAR}/${M ONTH}
for file in *
do
cat $file >>combined.report
echo -------------------------- ---------- ---------- ---------- ---------- >>combined .report
done
I never said that ther eis some thing wrong with your method. As I mentioned before I don't know how do awk and I guess that's where the confusion came from. The following is what I am running now:
#!/bin/ksh
YEAR= `date '+%Y'`
MONTH=`date '+%y-%B'`
DAY=`date '+%d'`
BASE_DIR=/apps/logs/sct
#Check to make sure the Year and Month direcotries exist if not
#create the cureent year/month directory
cd ${BASE_DIR}
if [ -d ${YEAR} ]
then
if [ ! -e ${MONTH} ]
then
mkdir ${YEAR}/${MONTH}
fi
else
mkdir -p ${YEAR}/${MONTH}
fi
#Now move the files into the directory.
cp *.---.---.com /apps/logs/sct/${YEAR}/${M
#Combined all the file into one file called mergedfile
cat ecs45h1 >mergedfile
cat ecs49n >>mergedfile
awk '($1=="Subject:")'{print "+++++++++++++++++++";prin
These are the error that I am getting?!?!?!?!? Any reason why?
mkdir: Failed to make directory "/05-July"; File exists
cp: /apps/logs/sct//05-July not found
cat: cannot open ecs45h1
cat: cannot open ecs49n
awk: syntax error near line 1
awk: illegal statement near line 1
Tintin,
when I used these line of code, it worked fine
#Change the directory and create a combined report
cd /apps/logs/sct/${YEAR}/${M
for file in *
do
cat $file >>combined.report
echo --------------------------
done
> mkdir: Failed to make directory "/05-July"; File exists
that's 'cause you have wrong syntax in seting your variables YEAR and MONTH, please remove any white space arround =
> cp: /apps/logs/sct//05-July not found
a follow up of the previous one
> cat: cannot open ecs45h1
well, that's something to check for you
> awk: syntax error near line 1
oops, missed the closing quote, sorry.
use:
awk '($1=="Subject:")'{print "+++++++++++++++++++";prin t;print "+++++++++++++++++++"}' file-containing-subject >> merged-file
and dont forget to fill in *your* valid filenames for file-containing-subject and merged-file
> when I used these line of code, it worked fine
probably you need to have such a loop arround your list of file in your previous code snippet
that's 'cause you have wrong syntax in seting your variables YEAR and MONTH, please remove any white space arround =
> cp: /apps/logs/sct//05-July not found
a follow up of the previous one
> cat: cannot open ecs45h1
well, that's something to check for you
> awk: syntax error near line 1
oops, missed the closing quote, sorry.
use:
awk '($1=="Subject:")'{print "+++++++++++++++++++";prin
and dont forget to fill in *your* valid filenames for file-containing-subject and merged-file
> when I used these line of code, it worked fine
probably you need to have such a loop arround your list of file in your previous code snippet
ASKER
Ahoffman,
here is what I run:
rm merged.report
for file in *
do
awk '($1=="Subject:")'{print "+++++++++++++++++++";prin t;print "+++++++++++++++++++"}*.pd 9.ford.com >>merged.r eport
done
This is the error that I get: around 40 of them!
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
Do you know why?
here is what I run:
rm merged.report
for file in *
do
awk '($1=="Subject:")'{print "+++++++++++++++++++";prin
done
This is the error that I get: around 40 of them!
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
Do you know why?
awk '($1=="Subject:")'{print "+++++++++++++++++++";prin t;print "+++++++++++++++++++"}*.pd 9.ford.com >>merged.r eport
should be
awk '($1=="Subject:")'{print "+++++++++++++++++++";prin t;print "+++++++++++++++++++"}' $file >>merged.report
should be
awk '($1=="Subject:")'{print "+++++++++++++++++++";prin
ASKER
Still syntax error?!?!
for file in *
do
awk '($1=="Subject:")' '{print"++++++++++++++++++ +";print;p rint"+++++ ++++++++++ ++++"}'$fi le>>merged .report
done
ERRORS:
awk: syntax error near line 1
awk: bailing out near line 1
Here is another line with different syntax error?!?!
for file in *
do
awk '($1=="Subject:")'{print"+ ++++++++++ ++++++++"; print;prin t"++++++++ ++++++++++ +"}'$file> >merged.re port
done
ERRORS:
./test.sh[59]: syntax error at line 61 : `'' unmatched
for file in *
do
awk '($1=="Subject:")' '{print"++++++++++++++++++
done
ERRORS:
awk: syntax error near line 1
awk: bailing out near line 1
Here is another line with different syntax error?!?!
for file in *
do
awk '($1=="Subject:")'{print"+
done
ERRORS:
./test.sh[59]: syntax error at line 61 : `'' unmatched
awk '($1=="Subject:"){print "+++++++++++++++++++";prin t;print "+++++++++++++++++++"}' $file >>merged.report
ASKER
Same thing!!!!
awk: syntax error near line 1
awk: bailing out near line 1
awk: syntax error near line 1
awk: bailing out near line 1
unbelievable, works for me
ASKER
Why do I have to run this twice to be able to create combined.report file? If the file does not exist yet, it will give me this error:
./test.sh
combined.report: No such file or directory
Is there anyway to fix this?
Thanks,
Leyla
************************** ********** ********** ********** ********** ********** ********** ****
#!/bin/ksh
YEAR=`date '+%Y'`
MONTH=`date '+%y-%B'`
DAY=`date '+%d'`
BASE_DIR=/apps/logs/sct
########################## ########## ########## ########## ########## ########## #
#Check to make sure that current Year and Month direcotries exist #
#and if not create one #
########################## ########## ########## ########## ########## ########## #
cd ${BASE_DIR}
if [ -d ${YEAR} ]
then
if [ -d ${YEAR}/${MONTH} ]
then
:
else
mkdir ${YEAR}/${MONTH}
fi
else
mkdir -p ${YEAR}/${MONTH}
fi
########################## ########## #######
#Now move the files into the directory #
########################## ########## #######
cp *.pd9.ford.com /apps/logs/sct/${YEAR}/${M ONTH}
########################## ########## ########## ########## ##
#Change the directory and create a combined report in #
# /apps/logs/sct/${YEAR}/${M ONTH} #
########################## ########## ########## ########## ##
cd /apps/logs/sct/${YEAR}/${M ONTH}
rm combined.report
for file in *
do
pr -f $file >>combined.report
echo -------------------------- ---------- ---------- ---------- ---------- ---------- ->>combine d.report
done
./test.sh
combined.report: No such file or directory
Is there anyway to fix this?
Thanks,
Leyla
**************************
#!/bin/ksh
YEAR=`date '+%Y'`
MONTH=`date '+%y-%B'`
DAY=`date '+%d'`
BASE_DIR=/apps/logs/sct
##########################
#Check to make sure that current Year and Month direcotries exist #
#and if not create one #
##########################
cd ${BASE_DIR}
if [ -d ${YEAR} ]
then
if [ -d ${YEAR}/${MONTH} ]
then
:
else
mkdir ${YEAR}/${MONTH}
fi
else
mkdir -p ${YEAR}/${MONTH}
fi
##########################
#Now move the files into the directory #
##########################
cp *.pd9.ford.com /apps/logs/sct/${YEAR}/${M
##########################
#Change the directory and create a combined report in #
# /apps/logs/sct/${YEAR}/${M
##########################
cd /apps/logs/sct/${YEAR}/${M
rm combined.report
for file in *
do
pr -f $file >>combined.report
echo --------------------------
done
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That works fine, thanks.
Now I am getting a little bit problem with the format of the report :( Here is how the report will look like when it's merged:
Jul 11 14:12 2005 2005-Jul-1-batch.---.---.c om Page 1
==== START run_cron monthly on batch === Fri Jul 1 05:05:05 EDT 2005
Summary File /var/sct/logs/monthly.2005 0701.sum.0 1
For details refer to Log File:
/var/sct/logs/monthly.2005 0701.log.0 1
su_chk Warning : 11 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog rams Display : 10 List of SUID Programs
=== END run_cron monthly on batch === Fri Jul 1 05:12:58 EDT 2005
=== 0 Error(s) and 1 Warning(s) ===
^L------------------------ ---------- ---------- ---------- ---------- ---------- ---
Jul 11 14:12 2005 2005-Jul-1-batch1.---.---. com Page 1
==== START run_cron monthly on batch1 === Fri Jul 1 05:05:01 EDT 2005
Summary File /var/sct/logs/monthly.2005 0701.sum.0 1
For details refer to Log File:
/var/sct/logs/monthly.2005 0701.log.0 1
audit_filesys Warning : 13 files are not owned by a recognized owner or group
su_chk Warning : 5 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog rams Display : 1 List of SGID Programs
List_of_SGID_and_SUID_Prog rams Display : 9 List of SUID Programs
=== END run_cron monthly on batch1 === Fri Jul 1 05:08:13 EDT 2005
=== 0 Error(s) and 2 Warning(s) ===
^L------------------------ ---------- ---------- ---------- ---------- ---------- ---
Jul 11 14:12 2005 2005-Jul-1-batch2.---.---. com Page 1
==== START run_cron monthly on batch2 === Fri Jul 1 05:05:02 EDT 2005
Summary File /var/sct/logs/monthly.2005 0701.sum.0 1
For details refer to Log File:
/var/sct/logs/monthly.2005 0701.log.0 1
List_of_SGID_and_SUID_Prog rams Display : 1 List of SGID Programs
List_of_SGID_and_SUID_Prog rams Display : 6 List of SUID Programs
=== END run_cron monthly on batch2 === Fri Jul 1 05:09:29 EDT 2005
=== 0 Error(s) and 0 Warning(s) ===
^L------------------------ ---------- ---------- ---------- ---------- ---------- ---
Jul 11 14:12 2005 2005-Jul-1-batch3.---.---. com Page 1
==== START run_cron monthly on batch3 === Fri Jul 1 05:05:04 EDT 2005
Summary File /var/sct/logs/monthly.2005 0701.sum.0 1
For details refer to Log File:
/var/sct/logs/monthly.2005 0701.log.0 1
su_chk Warning : 1 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog rams Display : 1 List of SGID Programs
List_of_SGID_and_SUID_Prog rams Display : 4 List of SUID Programs
=== END run_cron monthly on batch3 === Fri Jul 1 05:09:23 EDT 2005
=== 0 Error(s) and 1 Warning(s) ===
^L------------------------ ---------- ---------- ---------- ---------- ---------- ---
I run the following script to create this report:
#!/bin/ksh
YEAR=`date '+%Y'`
MONTH=`date '+%y-%B'`
DAY=`date '+%d'`
BASE_DIR=/apps/logs/sct
########################## ########## ########## ########## ########## ########## #
#Check to make sure that current Year and Month direcotries exist #
#and if not create one #
########################## ########## ########## ########## ########## ########## #
cd ${BASE_DIR}
if [ -d ${YEAR} ]
then
if [ -d ${YEAR}/${MONTH} ]
then
:
else
mkdir ${YEAR}/${MONTH}
fi
else
mkdir -p ${YEAR}/${MONTH}
fi
########################## ########## #######
#Now move the files into the directory #
########################## ########## #######
cp *.pd9.ford.com /apps/logs/sct/${YEAR}/${M ONTH}
########################## ########## ########## ########## ##
#Change the directory and create a combined report in #
# /apps/logs/sct/${YEAR}/${M ONTH} #
########################## ########## ########## ########## ##
cd /apps/logs/sct/${YEAR}/${M ONTH}
rm -f combined.report
for file in *
do
pr -f $file >>combined.report
echo -------------------------- ---------- ---------- ---------- ---------- ---------- ->>combine d.report
done
I want to change the format of the reports as following:
batch.---.---.com
su_chk Warning : 11 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog rams Display : 10 List of SUID Programs
-------------------------- ---------- ---------- ---------- ---------- ---------- -
batch1.---.---.com
audit_filesys Warning : 13 files are not owned by a recognized owner or group
su_chk Warning : 5 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog rams Display : 1 List of SGID Programs
List_of_SGID_and_SUID_Prog rams Display : 9 List of SUID Programs
-------------------------- ---------- ---------- ---------- ---------- ---------- -
batch2.---.---.com
List_of_SGID_and_SUID_Prog rams Display : 1 List of SGID Programs
List_of_SGID_and_SUID_Prog rams Display : 6 List of SUID Programs
-------------------------- ---------- ---------- ---------- ---------- ---------- -
batch3.---.---.com
su_chk Warning : 1 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog rams Display : 1 List of SGID Programs
List_of_SGID_and_SUID_Prog rams Display : 4 List of SUID Programs
-------------------------- ---------- ---------- ---------- ---------- ---------- -
batch, batch1, batch2, batch3 are 3 servers that we have in our system. The report will include around 60 servers with the following name format 2005-Jul-1-<server name>.---.---.com which will copy and merge them into combined.report file.
Is there any way that I can create my report as it is shown above with the only the server name as title?
Now I am getting a little bit problem with the format of the report :( Here is how the report will look like when it's merged:
Jul 11 14:12 2005 2005-Jul-1-batch.---.---.c
==== START run_cron monthly on batch === Fri Jul 1 05:05:05 EDT 2005
Summary File /var/sct/logs/monthly.2005
For details refer to Log File:
/var/sct/logs/monthly.2005
su_chk Warning : 11 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog
=== END run_cron monthly on batch === Fri Jul 1 05:12:58 EDT 2005
=== 0 Error(s) and 1 Warning(s) ===
^L------------------------
Jul 11 14:12 2005 2005-Jul-1-batch1.---.---.
==== START run_cron monthly on batch1 === Fri Jul 1 05:05:01 EDT 2005
Summary File /var/sct/logs/monthly.2005
For details refer to Log File:
/var/sct/logs/monthly.2005
audit_filesys Warning : 13 files are not owned by a recognized owner or group
su_chk Warning : 5 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog
List_of_SGID_and_SUID_Prog
=== END run_cron monthly on batch1 === Fri Jul 1 05:08:13 EDT 2005
=== 0 Error(s) and 2 Warning(s) ===
^L------------------------
Jul 11 14:12 2005 2005-Jul-1-batch2.---.---.
==== START run_cron monthly on batch2 === Fri Jul 1 05:05:02 EDT 2005
Summary File /var/sct/logs/monthly.2005
For details refer to Log File:
/var/sct/logs/monthly.2005
List_of_SGID_and_SUID_Prog
List_of_SGID_and_SUID_Prog
=== END run_cron monthly on batch2 === Fri Jul 1 05:09:29 EDT 2005
=== 0 Error(s) and 0 Warning(s) ===
^L------------------------
Jul 11 14:12 2005 2005-Jul-1-batch3.---.---.
==== START run_cron monthly on batch3 === Fri Jul 1 05:05:04 EDT 2005
Summary File /var/sct/logs/monthly.2005
For details refer to Log File:
/var/sct/logs/monthly.2005
su_chk Warning : 1 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog
List_of_SGID_and_SUID_Prog
=== END run_cron monthly on batch3 === Fri Jul 1 05:09:23 EDT 2005
=== 0 Error(s) and 1 Warning(s) ===
^L------------------------
I run the following script to create this report:
#!/bin/ksh
YEAR=`date '+%Y'`
MONTH=`date '+%y-%B'`
DAY=`date '+%d'`
BASE_DIR=/apps/logs/sct
##########################
#Check to make sure that current Year and Month direcotries exist #
#and if not create one #
##########################
cd ${BASE_DIR}
if [ -d ${YEAR} ]
then
if [ -d ${YEAR}/${MONTH} ]
then
:
else
mkdir ${YEAR}/${MONTH}
fi
else
mkdir -p ${YEAR}/${MONTH}
fi
##########################
#Now move the files into the directory #
##########################
cp *.pd9.ford.com /apps/logs/sct/${YEAR}/${M
##########################
#Change the directory and create a combined report in #
# /apps/logs/sct/${YEAR}/${M
##########################
cd /apps/logs/sct/${YEAR}/${M
rm -f combined.report
for file in *
do
pr -f $file >>combined.report
echo --------------------------
done
I want to change the format of the reports as following:
batch.---.---.com
su_chk Warning : 11 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog
--------------------------
batch1.---.---.com
audit_filesys Warning : 13 files are not owned by a recognized owner or group
su_chk Warning : 5 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog
List_of_SGID_and_SUID_Prog
--------------------------
batch2.---.---.com
List_of_SGID_and_SUID_Prog
List_of_SGID_and_SUID_Prog
--------------------------
batch3.---.---.com
su_chk Warning : 1 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog
List_of_SGID_and_SUID_Prog
--------------------------
batch, batch1, batch2, batch3 are 3 servers that we have in our system. The report will include around 60 servers with the following name format 2005-Jul-1-<server name>.---.---.com which will copy and merge them into combined.report file.
Is there any way that I can create my report as it is shown above with the only the server name as title?
# something like:
awk '(NF>3){if($(NF-1)=="Page" ){f=$(NF-2 );print f;next}}/attempt/{print;ne xt}/rogram s/{print;n ext}/----- -----/{pri nt;next}EN D{print f}' $file >>combined.report
# to be improved in many ways
awk '(NF>3){if($(NF-1)=="Page"
# to be improved in many ways
ASKER
awk '(NF>3){if($(NF-1)=="Page" ){f=$(NF-2 );print f;next}}/attempt/{print;ne xt}/rogram s/{print;n ext}/----- -----/{pri nt;next}EN D{print f}' $file >>combined.report
Unfortunately, it doesn't give the format that I am looking for. The following line is what I used your suggestions and came up with:
for file in `ls -1t *.pd9.com`
do
cat $file >> combined.report
echo ${file} | awk -F"-" ' { print $4} '| awk -F"." ' { print $1} ' >> combined.report
echo -------------------------- ---------- ---------- ---------- ---------- ---------- ->>combine d.report
done
But not exactly right yet. It's getting very close though. Here is what I get when I run it:
==== START run_cron monthly on batch === Fri Jul 1 05:05:05 EDT 2005
Summary File /var/sct/logs/monthly.2005 0701.sum.0 1
For details refer to Log File:
/var/sct/logs/monthly.2005 0701.log.0 1
su_chk Warning : 11 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog rams Display : 10 List of SUID Programs
=== END run_cron monthly on batch === Fri Jul 1 05:12:58 EDT 2005
=== 0 Error(s) and 1 Warning(s) ===
batch
-------------------------- ---------- ---------- ---------- ---------- ---------- -
==== START run_cron monthly on batch1 === Fri Jul 1 05:05:01 EDT 2005
Summary File /var/sct/logs/monthly.2005 0701.sum.0 1
For details refer to Log File:
/var/sct/logs/monthly.2005 0701.log.0 1
audit_filesys Warning : 13 files are not owned by a recognized owner or group
su_chk Warning : 5 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog rams Display : 1 List of SGID Programs
List_of_SGID_and_SUID_Prog rams Display : 9 List of SUID Programs
=== END run_cron monthly on batch1 === Fri Jul 1 05:08:13 EDT 2005
=== 0 Error(s) and 2 Warning(s) ===
batch1
-------------------------- ---------- ---------- ---------- ---------- ---------- -
Any help?
Unfortunately, it doesn't give the format that I am looking for. The following line is what I used your suggestions and came up with:
for file in `ls -1t *.pd9.com`
do
cat $file >> combined.report
echo ${file} | awk -F"-" ' { print $4} '| awk -F"." ' { print $1} ' >> combined.report
echo --------------------------
done
But not exactly right yet. It's getting very close though. Here is what I get when I run it:
==== START run_cron monthly on batch === Fri Jul 1 05:05:05 EDT 2005
Summary File /var/sct/logs/monthly.2005
For details refer to Log File:
/var/sct/logs/monthly.2005
su_chk Warning : 11 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog
=== END run_cron monthly on batch === Fri Jul 1 05:12:58 EDT 2005
=== 0 Error(s) and 1 Warning(s) ===
batch
--------------------------
==== START run_cron monthly on batch1 === Fri Jul 1 05:05:01 EDT 2005
Summary File /var/sct/logs/monthly.2005
For details refer to Log File:
/var/sct/logs/monthly.2005
audit_filesys Warning : 13 files are not owned by a recognized owner or group
su_chk Warning : 5 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog
List_of_SGID_and_SUID_Prog
=== END run_cron monthly on batch1 === Fri Jul 1 05:08:13 EDT 2005
=== 0 Error(s) and 2 Warning(s) ===
batch1
--------------------------
Any help?
awk '/^===/{next;}(NF>3){if($( NF-1)=="Pa ge"){f=$(N F-2);print f;next}}/attempt/{print;ne xt}/rogram s/{print;n ext}/----- -----/{pri nt;next}EN D{print f}' $file >>combined.report
ASKER
Not doing any thing!
ASKER
This for loop is what I could have worked on to be able to create the format that I am looking for. But my egrep doesn't work properly :( Anyone knows why?
for file in `ls -1t *.---.com`
do
server=`echo ${file} | awk -F"-" ' { print $4} '| awk -F"." ' { print $1} ' `
echo " " >> combined.report
echo " Server *${server}* report:" >> combined.report
egrep -v "==|From:|Sent:|To:|Subjec t:|File:|r efer" ${file} >> combined.report
echo -------------------------- ---------- ---------- ---------- ---------- ---------- ->>combine d.report
done
This is what it returns:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---
Server *batch* report:
Summary File /var/sct/logs/monthly.2005 0701.sum.0 1
/var/sct/logs/monthly.2005 0701.log.0 1
su_chk Warning : 11 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog rams Display : 10 List of SUID Programs
-------------------------- ---------- ---------- ---------- ---------- ---------- -
Server *batch1* report:
Summary File /var/sct/logs/monthly.2005 0701.sum.0 1
/var/sct/logs/monthly.2005 0701.log.0 1
audit_filesys Warning : 13 files are not owned by a recognized owner or group
su_chk Warning : 5 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog rams Display : 1 List of SGID Programs
List_of_SGID_and_SUID_Prog rams Display : 9 List of SUID Programs
And for some reason my egrep does not work on the following lines:
Summary File /var/sct/logs/monthly.2005 0701.sum.0 1
/var/sct/logs/monthly.2005 0701.log.0 1
for file in `ls -1t *.---.com`
do
server=`echo ${file} | awk -F"-" ' { print $4} '| awk -F"." ' { print $1} ' `
echo " " >> combined.report
echo " Server *${server}* report:" >> combined.report
egrep -v "==|From:|Sent:|To:|Subjec
echo --------------------------
done
This is what it returns:
--------------------------
Server *batch* report:
Summary File /var/sct/logs/monthly.2005
/var/sct/logs/monthly.2005
su_chk Warning : 11 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog
--------------------------
Server *batch1* report:
Summary File /var/sct/logs/monthly.2005
/var/sct/logs/monthly.2005
audit_filesys Warning : 13 files are not owned by a recognized owner or group
su_chk Warning : 5 failed su login attempt(s) to root found.
List_of_SGID_and_SUID_Prog
List_of_SGID_and_SUID_Prog
And for some reason my egrep does not work on the following lines:
Summary File /var/sct/logs/monthly.2005
/var/sct/logs/monthly.2005
egrep works on these lines, means they're returned
ASKER
Is there any thing else that I can use instead of my egrep to remove the following lines in each report before I send them in combined.report file?
==== START run_cron monthly on batch1 === Fri Jul 1 05:05:01 EDT 2005
Summary File /var/sct/logs/monthly.2005 0701.sum.0 1
For details refer to Log File:
/var/sct/logs/monthly.2005 0701.log.0 1
=== END run_cron monthly on batch1 === Fri Jul 1 05:08:13 EDT 2005
=== 0 Error(s) and 2 Warning(s) ===
==== START run_cron monthly on batch1 === Fri Jul 1 05:05:01 EDT 2005
Summary File /var/sct/logs/monthly.2005
For details refer to Log File:
/var/sct/logs/monthly.2005
=== END run_cron monthly on batch1 === Fri Jul 1 05:08:13 EDT 2005
=== 0 Error(s) and 2 Warning(s) ===
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>awk '/^===/{next}($0~/monthly/ ){next}/re fer to Log File/{next}'
Hangs on when I add this into my codes!!
Hangs on when I add this into my codes!!
ASKER
Any one knows what is wrong with my egrep?
egrep -v "==|Summary:|For" ${file} >> combined.report
egrep -v "==|Summary:|For" ${file} >> combined.report
ASKER
Cheers, my egrep finally started to work and thanks Tintin for your help on showing me how to merge my files.
cat ecs51h2 > mergedfile
cat nicdev2 >> mergedfile
> any way I can make changes to the format of each files before it's sent to the merged file.
pipe file through awk, perl, sed, tr or whatever you feel comfortable
> As you see each file has a subject which I want to add some border around each one by using +
awk '($1=="Subject:"){print "+++++++++++++++++++";prin
> In a simple way, I want to format the merge file some how that can be easy to read.
easy to read by what/whom? humans, machines?
what is the definition of "easy"?
BTW your code:
> if [ -e ${YEAR} ]
checks for existance, hence if a file exists named $YEAR your following mkdir command fails, you better check liek:
if [ -d ${YEAR} ]