this is the format of the log file in my system
xxxxx_xxx_xxxx_xxxxx_09_10_2009_170457.log
xxxx_xxx_2_0_09_10_2009_163834.log
xxx_xxxxxxxxx_25_10_2009_045020.log
xxx_xxxxxxx_08_11_2009_055728.log
the path of this logs file in on for example
/dellxmax/application/log
what i want to do is
make script
give me this output
----------------------------------------------------------------------
File Name | status | date
----------------------------------------------------------------------
xxxxx_xxx_xxxx_xxxxx_09_10_2009_170457.log | success | 22_10_2009
xxxx_xxx_2_0_09_10_2009_163834.log | success | 22_10_2009
xxx_xxxxxxxxx_25_10_2009_045020.log | success | 22_10_2009
xxx_xxxxxxx_08_11_2009_055728.log | success | 22_10_2009
in this report i want the arrange ascending (the last file modified is the last one in this report)
for the status i want this script search for Successfully in the file
founded give me successfully
if it doesn't give me fail
thanks in advance
try this let me know if it helps, this is assuming you have the "stat" installed
I did this on a CentOS machine. If I understood your post this is what you are looking for just need to tweak it if needed but now you might have the idea.
#!/bin/bash
counta=1
for file in /dellxmax/application/log/*
do
DC=$(stat -c %y $file | awk {' print $1'})
STATUSLOG=$(grep 'success' $file)
if [ "$?" -eq 0 ]
then
ST="success";
else
ST="failed";
fi
echo "$counta) $file | $ST | $DC";
counta=`expr $counta + 1`;
done
let me know how it goes
this is the output of the script
1016) /dellxmax/application/log/xxxxxx_xxxxxx_17_06_2009_041723.log | success | 2009-11-11
1017) /dellxmax/application/log/xxxxxx_xxxxxx_18_09_2009_150922.log | success | 2009-11-11
1018) /dellxmax/application/log/xxxxxx_xxxxxx_23_06_2009_022126.log | success | 2009-11-11
1019) /dellxmax/application/log/xxxxxx_xxxxxx_23_07_2009_030918.log | success | 2009-11-11
1020) /dellxmax/application/log/xxxxxx_xxxxxx_26_08_2009_211545.log | success | 2009-11-11
1021) /dellxmax/application/log/xxxxxx_xxxxxx_28_09_2009_090610.log | success | 2009-11-11
1022) /dellxmax/application/log/xxxxxx_xxxxxx_29_06_2009_034650.log | success | 2009-11-11
1- i appreciate your help very very thank you
2- i need some edit for the output
- all of this log for the same job run if dufferient days i want to replace 2009-11-11 with the date of the log for example
1022) /dellxmax/application/log/xxxxxx_xxxxxx_29_06_2009_034650.log | success | 29.06.2009:034650
- when you run this command ls -ltr all file sorted
-l long list format
-t Sorts by time stamp (latest first)
-r Reverses the order of sort
So when I do this command the last created depending on time stamp will be the last file in the list
I want this script have the same concept of the command
- the script search for successfully else put failed
- i want to enter another condition and the first condition also running the secand condition is search for dellxmax in the file found write done in the status not found write ndone in the status
totally i would like to thanks you very much for this script
try this:
#!/bin/bash
counta=1
CMD="ls -tr /dellxmax/application/log/"
for file in `$CMD`
do
DC=$(echo $file | awk '{ print substr( $0, length($0) - 20, length($0) ) }' | sed 's/.log//g' | sed 's/_/./g')
STATUSLOG=$(grep 'success' $file)
if [ "$?" -eq 0 ]
then
ST="success";
else
ST="failed";
fi
echo "$counta) $file | $ST | $DC";
counta=`expr $counta + 1`;
done
your log files has to be consistent since this will grab the last 21 characters from the log file name, btw, if you want to remove the counta you could and you won't get the line number on each output.
if you need further editing to the script, try doing it yourself and post it here and I will do my best to help you out
let me know if this helped
#!/bin/bash
set +x
counta=1
TODAY=`date +%d_%m_%Y_`
CMD=`ls -1tr /dellxmax/application/log/*${TODAY}*.log`
for file in $CMD
do
DC=$(echo $file | awk '{ print substr( $0, length($0) - 20, length($0) ) }' | sed 's/.log//g' | sed 's/_/./g')
STATUSLOG=$(egrep "success|fine" $file)
if [ "$?" -eq 0 ]
then
ST="success";
else
ST="failed";
fi
echo "$counta) $file | $ST | $DC";
counta=`expr $counta + 1`;
done
very thanks for you the script is run and i add to make this script run for today day only
to prevent the previous log file
very thanks for you
thanks last request
i will going to learn shell script
please provide me to good manual for beginner
for shell script & awk % sed
Glad to help.
A book I have "kind of old (2003)" but good, is the "Unix Shell Programming, third edition" Stephen G. Kochan and Patrick Wood
But online you will find many tutorials. You can also browse through unix.com and look at people's problems and see the developed solution and try to analise it.
See you around.