Visit Our UNIX and Linux User Community


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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help on unix scripting. I am at hello world level. Your help would be greatly appreciated.
# 1  
Old 08-16-2012
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
Code:
=> 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.


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-16-2012 at 10:24 AM.. Reason: code tags
# 2  
Old 08-16-2012
Try:
Code:
[ $(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

This User Gave Thanks to zaxxon For This Post:
# 3  
Old 08-16-2012
Something like this?
Code:
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


Last edited by elixir_sinari; 08-16-2012 at 11:28 AM..
This User Gave Thanks to elixir_sinari For This Post:
# 4  
Old 08-16-2012
Hi Zaxxon,

the logfiles are getting generated on daily basis in the format ULOG.mmddyy . In this case how to automate through shell script?
# 5  
Old 08-16-2012
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:
Code:
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


Last edited by zaxxon; 08-16-2012 at 11:01 AM.. Reason: adding code
This User Gave Thanks to zaxxon For This Post:
# 6  
Old 08-16-2012
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?

Last edited by krchakr; 08-16-2012 at 11:07 AM..
# 7  
Old 08-16-2012
Quote:
could you please do me a favor in writing the entire code snippet for me.
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 Smilie
This User Gave Thanks to zaxxon For This Post:

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. What is on Your Mind?

Mad World Remix of Moby Video (Are You Lost In The World Like Me)

This is an excellent video comment on modern society and the remix is good too: https://www.youtube.com/watch?v=5DU1B_XkyIk 5DU1B_XkyIk Watch the video above and post your comments. (3 Replies)
Discussion started by: Neo
3 Replies

2. Homework & Coursework Questions

Help would be appreciated

If anyone could possibly help me to do this following question? Print a long listing of the files in the login directory for a specific month. The user is prompted to enter the first 3 letters of a month name, starting with a capital, and the program will display a long list of all files that... (1 Reply)
Discussion started by: Zunifx
1 Replies

3. UNIX for Dummies Questions & Answers

Had this idea for years, any help at all would be greatly appreciated!

Hello everyone, For a while now ive been wanting to create a way for me to access my home pc and have it perform remote tasks (Namely file downloading, archiving, torrenting) without needing to keep the PC continuously powered. Having seen the power of Linux and ssh at the hands of... (1 Reply)
Discussion started by: spliffinz
1 Replies

4. UNIX for Dummies Questions & Answers

Unix in the banking world

Hi I have recently joined a bank as a tester. Initially I will be working on some test scripts and then I will be testing their data warehouse using SQL and Unix. I do have a very basic knowledge and understanding of both unix and sql. I am not sure how I will be using Unix to test their ... (2 Replies)
Discussion started by: kartikkumar84@g
2 Replies

5. UNIX for Dummies Questions & Answers

Click here for the best unix in the world!!!!

To anyone who asks which Unix is the best... or which one I should use... Probably the best timeline I have ever seen. Read this link... http://www.levenez.com/unix/history.html#08 (0 Replies)
Discussion started by: Kelam_Magnus
0 Replies

6. UNIX for Dummies Questions & Answers

new to unix world

Need a lot of help, need to find information on unix and how to use it, Has anybody ues the learnkey videos on unix teaching. (5 Replies)
Discussion started by: winter
5 Replies

Featured Tech Videos