How to compare datetime?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to compare datetime?
# 1  
Old 07-11-2012
How to compare datetime?

Hi,
To get the batch status, I will need to check if the particular job started after 5PM. if the job start time is before 5 pm, then it means that the job has not started for this particular date. I will run the script with date as argument.
For eg:
BS 07/10/2012
Start time from the log is 07/10/2012 08.30.02
So, it means that the above job has not started for the given date.

So, how do I check if the job has started after 17.00.00 ? How do I compare this datetime?

Thanks
Ajay
# 2  
Old 07-11-2012
What have you tried so far?
# 3  
Old 07-11-2012
I used the below code:
Code:
echo $today $job_start_date | awk '
BEGIN {
        d[1]= 31
        d[2]= 28
        d[3]= 31
        d[4]= 30
        d[5]= 31
        d[6]= 30
        d[7]= 31
        d[8]= 31
        d[9]= 30
        d[10]= 31
        d[11]= 30
        d[12]= 31
}
{
        yr=substr($1,7,2); mon=substr($1,1,2); day=substr($1,4,2)
        yr1=substr($2,7,2); mon1=substr($2,1,2);day1=substr($2,4,2)
        if((yr % 4 ==0 && yr % 100 !=0) || yr % 400 ==0) { d["02"] = 29;}
        if ((yr1 - yr)==0 && (mon1-mon)==0 && (day1-day)==0)
        {
        echo $job_start_time
#       st_time=$((`echo $job_start_time|sed 's/.//g'`))
#       echo $st_time
                }
}'

Got the below error when running:
Code:
./BS 07/10/2012
awk: Field $() is not correct.
 The input line number is 1.
 The source line number is 24.
    Rockport|22:00|  PDWRCK01|07/10/2012|  22.00.16|
         WIM|00:05|  PDWIM000|07/11/2012|  00.05.01|

---------- Post updated at 04:45 AM ---------- Previous update was at 04:43 AM ----------

I got the job_start_time from the logs and I can post the complete code, if you want.
# 4  
Old 07-11-2012
Please show a line of the log for a particular job and explain the fields. Taking the output you posted
Code:
Rockport|22:00|  PDWRCK01|07/10/2012|  22.00.16

assuming | as field delimeter, is field 2 the specified starting time and the last field the time it actually started or when it ended?
# 5  
Old 07-11-2012
This is the entire code:
Code:
#!/bin/ksh
conf=BS.config
Appl=""
st_dt=""
end_dt=""
status=""
job_start_date=""
job_start_time=""
today=$1
exec<$conf
while read job
do
        set -A Arr $job
        appl=${Arr[0]}
        avg_st_time=${Arr[3]}
job1=${Arr[1]}
job_start_date=`grep $job1 /opt/CA/ca7/sche/log/ga016dcf/ca7en2.out|tail -2|head -1|cut -d " " -f11`
job_start_time=`grep $job1 /opt/CA/ca7/sche/log/ga016dcf/ca7en2.out|tail -2|head -1|cut -d " " -f12`
#echo $today $job_start_date | awk '
#BEGIN {
#       d[1]= 31
#       d[2]= 28
#       d[3]= 31
#       d[4]= 30
#       d[5]= 31
#       d[6]= 30
#       d[7]= 31
#       d[8]= 31
#       d[9]= 30
#       d[10]= 31
#       d[11]= 30
#       d[12]= 31
#}
#{
#       yr=substr($1,7,4); mon=substr($1,1,2); day=substr($1,4,2)
#       yr1=substr($2,7,4); mon1=substr($2,1,2);day1=substr($2,4,2)
#       if((yr % 4 ==0 && yr % 100 !=0) || yr % 400 ==0) { d["02"] = 29;}
#       if ((yr1 - yr)==0 && (mon1-mon)==0 && (day1-day)==0)
#       {
#       echo $job_start_time
#       st_time=$((`echo $job_start_time|sed 's/.//g'`))
#       echo $st_time
#               }
#}'

printf "%12s|%5s|%10s|%10s|%10s|\n" $appl $avg_st_time $job1 $job_start_date $job_start_time
unset Arr
Appl=""
st_dt=""
end_dt=""
status=""
job_start_time=""
job_start_date=""
done
echo "\n\n"
exit 0

Config file:
Code:
Rockport        PDWRCK01        PDWRCK03        22:00
WIM     PDWIM000        PDWIM050        00:05

Sample log file:
Code:
grep PDWRAD ca7en2.out|tail -2
.CASH_I_0798 JOBINIT record being written for job 'PDWRADC2'   07/11/2012 04.18.04
.CASH_I_0799 JOBTERM record being written for job 'PDWRADC2'   07/11/2012 04.18.56


Last edited by zaxxon; 07-11-2012 at 06:07 AM.. Reason: some more code tags
# 6  
Old 07-11-2012
Is $1 ie. $today really today or just any date one can enter manually?
What is the config file good for? Explain the fields please. And please show a snippet of the log file that is related to some config entry, thanks.
# 7  
Old 07-11-2012
Our batch starts at 5PM and runs till next day ~1pm.
We manually give the batch process date which is $1.(We should be able to check the batch status for previous days as well and so passing it as argument).
I manually created the config file with fields like Apllication name, starting job, ending job, Avg start time.

Log file contains nothing but just the start time and end time.
Code:
head -5 ca7en2.out
.CASH_I_0077 ENF message queue = < 6>, key =< 3239>   06/18/2012 06.45.42
.CASH_I_0799 JOBTERM record being written for job 'PDWXX60'   06/18/2012 06.45.42
.CASH_I_0798 JOBINIT record being written for job 'PDWXXO3'   06/18/2012 07.00.05
.CASH_I_0798 JOBINIT record being written for job 'PDWXX07'   06/18/2012 07.10.15
.CASH_I_0798 JOBINIT record being written for job 'PDWXX010'   06/18/2012 07.10.21

JOBINIT is the start time and jobterm is the endtime.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filename with datetime

Hello All, I need unix command to generate a file with datetime in it. For example : ABC_YYYYMMDDHH24MISS.txt Regards Biswajeet Ghosh (1 Reply)
Discussion started by: bghosh
1 Replies

2. Shell Programming and Scripting

SunOS compare datetime

Hi i need to compare the datetime between 2 columns. SunOS 5.1 is used. Notice that mktime seems like not supported. cat file2 P1,2012 12 4 21 36 48,2012 12 4 22 26 53 P2,2012 12 4 20 36 48,2012 12 4 21 21 23 P3,2012 12 4 18 36 48,2012 12 4 20 12 35 Below is the command used.... (1 Reply)
Discussion started by: chailee
1 Replies

3. UNIX for Dummies Questions & Answers

Find files between two datetime..

Hi All, How do i find all the files between two times. Eg: 26 may 2014 06:00 to 26 may 2014 14:00 mmin and mtime gives for a specific period. we receive hundreds of files input directories and i need to find how many files are received between given specific datetime. Thanks. (2 Replies)
Discussion started by: abhi_123
2 Replies

4. Shell Programming and Scripting

Adding 48 hours to DateTime

Hey Guys, I have looked for a solution throughout the forum for my particular question, but I cant find one. So I'm sorry if I overlooked it. I need to be able to 48 add hours to a particular DateTime string. I have a variable named $startTime I would like to be able to take that... (1 Reply)
Discussion started by: chagan02
1 Replies

5. Shell Programming and Scripting

How to generate datetime string?

Hi. I'm hoping there is a simple method where I'm able to generate a datetime string that looks like this (yyyymmddhhmm): 201106280830 The tricky part would be that I need this string to be today's datetime minus 1 year. Is there anyway to do this? (3 Replies)
Discussion started by: buechler66
3 Replies

6. Shell Programming and Scripting

datetime difference in seconds

Hi, I'm trying to find processing time of my script. Please can someone give me the commands to get the start/end time in "dd-mm-yyyy hh:mm:ss" and the differnce in seconds. Thanks! (5 Replies)
Discussion started by: dvah
5 Replies

7. Programming

SQL datetime calculation

Suppose I have a mysql table consisting of measurements taken during irregular intervals as follows: CREATE TABLE data (datetime DATETIME, value INTEGER); mysql> SELECT datetime, value FROM data; +---------------------+---------+ | datetime | value |... (2 Replies)
Discussion started by: figaro
2 Replies

8. Shell Programming and Scripting

Awk new datetime everyline

Hi, I'm using awk in HP-UX machine which does not support systime(), strftime(). So to get the date time I was using : seq 1 100000 | awk ' "date +%Y%m%d%H%M%s" | getline curtime; print curtime }' However the above code gets the date only once, next time it is not updated. For... (2 Replies)
Discussion started by: Random_Net
2 Replies

9. Shell Programming and Scripting

datetime.pm

Hi, I'm trying to use datetime.pm function in Perl. I do not have in the library. Is there a way to get it and put it into library? Thanks, George. (1 Reply)
Discussion started by: gpaulose
1 Replies
Login or Register to Ask a Question