Need help on unix scripting. I am at hello world level. Your help would be greatly appreciated.

Need to automate the following steps (OS--> AIX )

  1. cd /advx/R8.1MR2/TOP/logs ( I navigate to this directory)
  2. Monitor the current date ULOG for specific error pattern
=> ls -lrt ULOG.08*
-rw-rw-rw-    1 vssrt    vssgrp        24370 Aug 01 23:57 ULOG.080112
-rw-rw-rw-    1 vssrt    vssgrp        26094 Aug 02 23:59 ULOG.080212
-rw-rw-rw-    1 vssrt    vssgrp        76357 Aug 03 23:46 ULOG.080312
-rw-rw-rw-    1 vssrt    vssgrp        21232 Aug 04 23:47 ULOG.080412
-rw-rw-rw-    1 vssrt    vssgrp        18235 Aug 05 23:49 ULOG.080512
-rw-rw-rw-    1 vssrt    vssgrp        45460 Aug 06 23:51 ULOG.080612
-rw-rw-rw-    1 vssrt    vssgrp        24888 Aug 07 23:52 ULOG.080712
-rw-rw-rw-    1 vssrt    vssgrp        23013 Aug 08 23:54 ULOG.080812
-rw-rw-rw-    1 vssrt    vssgrp        25403 Aug 09 23:56 ULOG.080912
-rw-rw-rw-    1 vssrt    vssgrp        24354 Aug 10 23:58 ULOG.081012
-rw-rw-rw-    1 vssrt    vssgrp        18289 Aug 11 23:59 ULOG.081112
-rw-rw-rw-    1 vssrt    vssgrp        18160 Aug 12 23:46 ULOG.081212
-rw-rw-rw-    1 vssrt    vssgrp        22486 Aug 13 23:47 ULOG.081312
-rw-rw-rw-    1 vssrt    vssgrp        22656 Aug 14 23:49 ULOG.081412
-rw-rw-rw-    1 vssrt    vssgrp        50666 Aug 15 23:51 ULOG.081512
-rw-rw-rw-    1 vssrt    vssgrp         6548 Aug 16 07:06 ULOG.081612

=> grep -ice "Invalid Transaction" ULOG.081612
0

Requirement is if it returns not equal to 0 or greater than 0 then mail the result to specific members.

Try:

[ $(grep -ic "Invalid Transaction" ULOG.081612) -gt 0 ] && \
grep -i "Invalid Transaction" ULOG.081612 |\
mail -s "tuxedo info" a@bla.net b@bla.net c@bla.net
1 Like

Something like this?

cd /advx/edgrt/R8.0g/TOP/logs
if grep -i "Invalid Transaction" ULOG.$(date +%m%d%y) >errors_today 2>/dev/null
then
 mail "someone@somehost" < errors_today
fi
1 Like

Hi Zaxxon,

the logfiles are getting generated on daily basis in the format ULOG.mmddyy . In this case how to automate through shell script?

See elixir_sinari's solution including the date command. You can also leave out the count with -c and just check the return status of grep with $? or go this way, checking if the variable $VAR is not empty (to not invoke grep twice:

A tad more elegant:

VAR="$(grep -i "Invalid Transaction" ULOG.$(date +%m%d%y) 2> /dev/null)"
[ -n "$VAR" ] && \
mail -s "tuxedo info" a@bla.net b@bla.net c@bla.net
1 Like

Hi Elixir,
Yes you are right. As i am new to scripting could you please do me a favor in writing the entire code snippet for me.

Also ULOG is located on the /advx/edgrt/R8.0g/TOP/logs . what will be the syntax please?

The spirit of the forum is to help of course, though we very welcome if posters seeking advice show some effort of their own, no matter how false it is.
You have some examples here now so please try to write the rest (if there is any) yourself and ask for particular problems if you get stuck. Please do not ask people to do the whole job for you :wink:

1 Like