The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
If Then Else Logic jadionne UNIX for Dummies Questions & Answers 7 11-23-2007 04:27 AM
cannot get the logic dineshr85 Shell Programming and Scripting 3 10-11-2007 08:34 AM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 10:52 PM
Automated FTP to variable directory with error check songtam UNIX for Dummies Questions & Answers 3 04-10-2006 10:57 AM
Status check of Automated FTP anijog Shell Programming and Scripting 5 03-04-2004 02:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-01-2008
senthilkumar_ak senthilkumar_ak is offline
Registered User
  
 

Join Date: Aug 2008
Location: Chennai
Posts: 43
Need logic for check automated Job work in awk or SED.

I have a Java program which will automatically trigger some scheduled job to update Db or some other work. I am tracking the jobs with log messages and finding out it is properly run or not. I want to write a script to capture it correctly on time.

Say Job1 is running on 15, 30, and 45 every hour then it leave an entry in the log file that “JOB1 is started”. Like this.

Example for hour 11:00 pm means –

Worker#Scheduler_Worker-3: 23:15:56 105 SendToCM: run() Entry

where “SendToCM: run() Entry” starting log message which Java program write in the log message, '23:15:56' is the time . I need to check the last hour 15 , 30, 45 min log files to find out the entry is their or not then I intimate via mail to me.

i have a logic but not tested yet. For 15 min I am checking with sed like this,

sed -n "/: $h:15:00/,/: $h:15:01/p" schedulerTrace .log > Job1.log

here $h contains the current hour and in the job1.log I’m checking again like

count=grep –c “SendToCM: run() Entry” Job1.log.

if count is zero then the JOB1 is not ran and I need to check exception.
But this logic is very oblique to me. Could you me please help me on finding out a correct logic for this.

Regards,
Senthilkumar.
  #2 (permalink)  
Old 09-01-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Why not ignore the seconds component completely and just do something like:


Code:
if grep -q ": $h:15.*SendToCM: run()" schedulerTrace.log
then
      echo job did run
else
      echo job did not run
fi


Last edited by Annihilannic; 09-01-2008 at 03:46 AM.. Reason: forgot the SendToCm part
  #3 (permalink)  
Old 09-01-2008
senthilkumar_ak senthilkumar_ak is offline
Registered User
  
 

Join Date: Aug 2008
Location: Chennai
Posts: 43
Fantastic Annihilannic,

thanks for your suggestion. One more thing.

Is it possible for me to check all 15, 30,45 entires in one grep or i want to use a separte one.

Senthil
  #4 (permalink)  
Old 09-01-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
So... you want to only run your check once an hour and see whether it has run three times?


Code:
if [[ "$(grep -Eqc ": $h:(15|30|45):.*SendToCM: run\(\)" schedulerTrace.log)" -eq 3 ]]
then
      echo job did run 3 times in the hour
else
      echo job did not run 3 times in the hour
fi

I'm assuming that there are only one day's worth of jobs in the log, otherwise of course you will match the previous day's jobs too.
  #5 (permalink)  
Old 09-04-2008
senthilkumar_ak senthilkumar_ak is offline
Registered User
  
 

Join Date: Aug 2008
Location: Chennai
Posts: 43
Well yes you're right, the log files contains only one day logs. But with this condition i wont be check the job when not ran, so i modified little and used like this , please let me know if done some thing wrong.

# Loop to check the Job1 <Send To CM started properly or not>
if [ $min -ge 1 -o $min -lt 30 ]; then
count=`grep -ic ": $hr:01.*SendToCM: Start:" $logpath`
elif [ $min -ge 30 -o $min -le 59 ]; then
count=`grep -ic ": $hr:30.*SendToCM: Start:" $logpath`
fi
if [ $count -eq 0 ]; then
echo -e "\nThe Job1 Send To CM is not started as schdueld at 1 and 30" >> mail.log
fi

i will mail the mail.log at last after checking for other jobs too
  #6 (permalink)  
Old 09-04-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
I see nothing obviously wrong there.
Closed Thread

Bookmarks

Tags
awk, grep or, sed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0