Extract Specific pattern - log file

Hello everyone,

I am on AIX (6.1). I can only use shell (ksh) script.

I can't do this on my own, so will do my best to explain my needs.I also do not know what is the best idea to make it work, so here is what I am thinking, but I may wrong.

I need help to extract info on a log. The info needed will only concern the day today. So the script must be able to know the date of the day TODAY, and extract the scpecific pattern

tar: xxxxxxxxxxxxxxxxxxx: No such file or directory 

The idea is to create shell script that could run on crontab 3 times a day. The script must be able to extract specific pattern for today day. Means if today is 2011/11/09 it won't get the pattern of yesterday for exemple. If the pattern doesn't not exist for today, it will exit.

Here is the date return format on the AIX :

Wed Nov  9 10:36:17 CUT 2011

As you can see, here is the date pattern written on the log file :

2011/10/21

Here is a sample of the log file :

  0+2011/10/20-06:10:06+ARCHIVER_FICHIERS+713+recup du SIZE_MAX_STAF OK 5000 5242880000
  load staf 3.2.4 : OK
  0+2011/10/21-06:10:12+ARCHIVER_FICHIERS+713+recup du SIZE_MAX_STAF OK 5000 5242880000
  load staf 3.2.4 : OK
  tar: GO_CONS_STR_QUA_2C_20100228T233231_20100301T010215_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T010215_20100301T023158_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T023158_20100301T040142_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T040142_20100301T053125_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T053125_20100301T070108_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T070108_20100301T083052_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T083052_20100301T100035_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T100035_20100301T113018_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T113018_20100301T130002_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T130002_20100301T142945_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T142945_20100301T155929_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T155929_20100301T172912_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T172912_20100301T185855_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T185855_20100301T202839_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T202839_20100301T215822_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T215822_20100301T232805_0001.IDF: No such file or directory
  tar: GO_CONS_STR_QUA_2C_20100301T232805_20100302T005751_0001.IDF: No such file or directory
  0+2011/10/22-06:10:17+ARCHIVER_FICHIERS+713+recup du SIZE_MAX_STAF OK 5000 5242880000
  load staf 3.2.4 : OK
  0+2011/10/23-06:10:11+ARCHIVER_FICHIERS+713+recup du SIZE_MAX_STAF OK 5000 5242880000
  load staf 3.2.4 : OK
  0+2011/11/08-23:00:39+MONITEUR+1713+Erreur SQL.
  9+2011/11/08-23:00:39+MONITEUR+1718+ORA-03113: end-of-file on communication channel
  +

the result needed must be for exemple :

tar: GO_CONS_STR_QUA_2C_20100228T233231_20100301T010215_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T010215_20100301T023158_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T023158_20100301T040142_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T040142_20100301T053125_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T053125_20100301T070108_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T070108_20100301T083052_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T083052_20100301T100035_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T100035_20100301T113018_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T113018_20100301T130002_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T130002_20100301T142945_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T142945_20100301T155929_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T155929_20100301T172912_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T172912_20100301T185855_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T185855_20100301T202839_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T202839_20100301T215822_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T215822_20100301T232805_0001.IDF: No such file or directory
tar: GO_CONS_STR_QUA_2C_20100301T232805_20100302T005751_0001.IDF: No such file or directory

I hope you will be able to help me.

Thank you much as I completly lost on this.

grep -E "tar.*$(date +%Y%m%d).*: No such file or directory" infile

(may be egrep rather than grep -E on AIX, I forget).

Thanks CarloM, but I can't make it work.

I fact, I was looking for something like getting the date of the day,

Wed Nov  9 10:36:17 CUT 2011

then format the date to match the date used in the log file

2011/11/09

then start to read the log file from the first line that match the date of the day.

and find if there is or not any pattern that will be :

tar: xxxxxxxxxxxxxxxxxxx: No such file or directory

.

If no math found the script will exit, if match found it will send me a mail.

Thanks for your help, please.

Ah, I thought the tar lines had today's date in them.

Try this:

awk -vADATE=$(date +%Y/%m/%d) '/ARCHIVER/ {inside=0} $0 ~ ADATE {inside=1} /tar:.*: No such file or directory/ { if (inside==1) {print}}' infile
1 Like