Need logic for check automated Job work in awk or SED.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need logic for check automated Job work in awk or SED.
# 1  
Old 09-01-2008
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  
Old 09-01-2008
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  
Old 09-01-2008
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  
Old 09-01-2008
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  
Old 09-04-2008
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  
Old 09-04-2008
I see nothing obviously wrong there.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automated SCP from a job?

Hi all - I have a script which runs on the OS level, but refuses to run as a cron or as an Oracle job. The Script is pretty straight forward: #!/bin/bash username="MyUsername" host="Remote.server" path="Remote.directory/files/*.*" password="MyPassword" expect -c " spawn /usr/bin/scp... (3 Replies)
Discussion started by: danimaltex
3 Replies

2. Shell Programming and Scripting

Cron Job Automated Email Alternatives?

Hi guys, not sure if this would be the right place for this but I dont where else it would go... I'm new to Unix too, so please bare with me :) I guess first up some background on the situation. We have some scripts that run as cron jobs which monitor and check the health, etc of our servers.... (2 Replies)
Discussion started by: BrianD
2 Replies

3. Shell Programming and Scripting

I need to do a work to my job, but i m new in script shell, someone can help with this..

I need to do a work to my job, but i m new in script shell, someone can help with this.. :confused: Description Bsafe The command creates a backup directory of each month at the command line (arguments of the script). The names of directories to copy will always be specified for the... (4 Replies)
Discussion started by: strshel
4 Replies

4. What is on Your Mind?

Volunteer Work When Out of a Computer Job?

I need opinion from other ! I finished high school for computer technician few months ago and now I can not find a job because I do not have any experience with servers , I know basic staff about Linux and Unix and Windows better (used three 4 years) (this is way I registered here at... (3 Replies)
Discussion started by: solaris_user
3 Replies

5. Shell Programming and Scripting

IDL job doesn't work from crontab

I have made a script to execute an IDL routine with the purpose to plot data on a fixed time. The problem is that when I include this script in the crontab to run it every night, the IDL part doesn't work (the other commands, like getting data from the database, are carried out though). This... (4 Replies)
Discussion started by: SharkM
4 Replies

6. UNIX for Dummies Questions & Answers

Automated FTP to variable directory with error check

Hi, automated FTP that have error check and each product FTP will used the same userid/password to post(transfer) the file(s) from their <product> directory at UNIX to their <product> folder at Windows. such senarios as follows: NOTE: ======= ** Variable ** * The <product> is variable... (3 Replies)
Discussion started by: songtam
3 Replies

7. Shell Programming and Scripting

Status check of Automated FTP

Hi, I've following code fragment as a part of 1 of my scripts. Function is supposed to perform automated ftp to designated host. Here are the details:- #! /usr/bin/ksh < some code> perform_ftp() { #Assume that file to transfer is available in current directory ... (5 Replies)
Discussion started by: anijog
5 Replies

8. UNIX for Dummies Questions & Answers

Simple cron job won't work

I have a script in a directory -say users/me/test/ It looks like this: # "bkup" - copies specified files to the user's ~/Backup # directory after checking for name conflicts. a=$(date +%T) cp $1 ~/test/Backup/$1.$a It copies file.txt from current directory and timestamps the name of it of... (4 Replies)
Discussion started by: coregan
4 Replies
Login or Register to Ask a Question