Comparing date and check minute difference


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing date and check minute difference
# 1  
Old 06-30-2012
Comparing date and check minute difference

Dear all, I'm stuck on Solaris 9 bash (I believe is quite different from Linux system) trying to find a solution.

I have one file named like:
Code:
120629-1750-TERZ81_AS_YTR.txt
YYMMDD-HH-MM-......

The script should compare the actual date with the one reported on the file name and then take an action if the differences is greater or lower then 1 minute. The structure is like this:

Code:
DIFF=ACTUAL_DATE-DATE_ON_FILE
IF DIFF > 1 or DIFF < 1        # Greater or lower then 1 minute
THEN
.....
FI

Could someone help me to calculate the difference in minute? Thanks!
# 2  
Old 06-30-2012
The minutes of actual time:
Code:
lo4:/export/home/vbe $ date +%M
32

You will have to find a way to choose the file name you want to extract the minutes (?)
but the idea:
Code:
lo4:/export/home/vbe/wks $ echo 120629-1750-TERZ81_AS_YTR.txt|cut -c 10,11
50

Now its simple arithmetics, I let you deal with...
# 3  
Old 06-30-2012
EDIT: Well, I just realized that the file are -1 minute compared to current date.
FILE DATE: 0630-2119 --- CURRENT DATE: 0630-2120

So the question is now simple, how can I have MMDD-HHMM - 1 minute ??

Last edited by Lord Spectre; 06-30-2012 at 04:24 PM..
# 4  
Old 06-30-2012
Quote:
if the differences is greater or lower then 1 minute
This reads as nonsense because any time matches this condition (except exactly equals).

Please post representative examples and explain the problem you are trying to solve, not the problems with your solution.

Last edited by methyl; 06-30-2012 at 05:37 PM.. Reason: oops. exact
# 5  
Old 07-01-2012
Quote:
Originally Posted by methyl
This reads as nonsense because any time matches this condition (except exactly equals). Please post representative examples and explain the problem you are trying to solve, not the problems with your solution.
Well, you're right. I'll try to explain better.
I have a log dir (contains statistical data) with many files like (120629-1750-TERZ81_AS_YTR.txt). These file are created every minute.

The script I coded just take the last log file with the following command:
Code:
stat_ytr=$(cd /var/opt/backup/; ls -t *TERZ81_AS_YTR.txt | head -1)

... then it extract the statistical counters!

But, if for some reason the system doesn't create any statistical data, with the above command, I always take the last file, that in this case is the same as previous script execution. So the statistical data is, in this case, not correct because the script take old data.

Since the log is created every minute, and the script runs from crontab every minute, what I need to do, is compare the actual date with the date present on filename. The problem is that the file is created one minute before the actual date, that's why I need to subtract 1 minute to actual date.

So, in other words, I need to take the actual date/time subtracting 1 minute and compare with the date/time extracted from filename.
What I cannot do is
subtracting 1 minute to the actual date!!!! Smilie


---------- Post updated 01-07-12 at 01:51 AM ---------- Previous update was 30-06-12 at 05:02 PM ----------

=====================================================

Well, I just realize that handling date with Solaris bash, is quite complicated.
So, I just using perl to formatting date :

Code:
perl -e 'use POSIX qw(strftime);  print strftime "%y%m%d-%H%M \n", localtime(time()+$ARGV[0]);' -- -60

Output: 120701-0847


Last edited by Lord Spectre; 07-01-2012 at 04:14 AM..
This User Gave Thanks to Lord Spectre For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Take minute per minute from a log awk

Hi, I've been trying to develop a script that performs the parsing of a log every 1 minute and then generating some statistics. I'm fairly new to programming and this is why I come to ask if I can lend a hand. this is my log: xxxx 16/04/2012 17:00:52 - xxxx714 - E234 - Time= 119 ms.... (8 Replies)
Discussion started by: jockx
8 Replies

2. Shell Programming and Scripting

Count of matched pattern occurences by minute and date in a log file

Anyone knows how to use AWK to achieve the following Sun Feb 12 00:41:01-00:41:59 Success:2 Fail:2 Sun Feb 12 00:42:01-00:42:59 Success:1 Fail:2 Sun Feb 12 01:20:01-01:20:59 Success:1 Fail:2 Mon Feb 13 22:41:01-22:41:59 Success:1 Fail:1 log file: Success Success Fail Fail ... (9 Replies)
Discussion started by: timmywong
9 Replies

3. UNIX for Dummies Questions & Answers

Comparing Output Date to Current System Date

Hi Guys, Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Fri Dec 16... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

4. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

5. UNIX for Dummies Questions & Answers

Perl add one minute to the given date

Hello Gurus, We have a query where we need to add one minute ( also we need to add 12 hrs in another query) to given date. we tried using some functionalities like 'perl -e @d= $run_dt + 600' . however we were not succeeded. Basically issue is we get date in following format "May18... (9 Replies)
Discussion started by: sandeeppvk
9 Replies

6. Shell Programming and Scripting

Joining paragraph and comparing the difference

Hi Power User,:) I have this tipe of file: file1: HEAD HAIR FINGER NAIL THUMB HEAD HAIR NOSE HEAD LEG ARM (0 Replies)
Discussion started by: anjas
0 Replies

7. Shell Programming and Scripting

Time difference in Minute in UNIX

is there any ways to get the time difference between 2 dates in UNIX? for example, For below date the outut should come 22 minutes startdate enddate ========= ======= 06/17/2008 13:25 06/17/2008 13:47 For, below date, the output should come 1462 minutes ... (5 Replies)
Discussion started by: Amit.Sagpariya
5 Replies

8. Shell Programming and Scripting

script check the users in SHELL every 1 minute ?

could you please find a solution for this: I need to write a shell script which checks after every minute whether a friend has logged in or not.The script should report whether that person has logged in along with the amount of time the person was late in logging in. I have no idea how to... (2 Replies)
Discussion started by: blunderblitz
2 Replies

9. Linux

Comparing the file drop date with todays date

Daily one file will dropped into this directory. Directory: /opt/app/jt/drop File name: XXXX_<timestamp>.dat.gz I need to write a script which checks whether the file is dropped daily or not. Any idea in the script how can we compare timestamp of the file to today's date?? (3 Replies)
Discussion started by: Rajneel
3 Replies

10. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies
Login or Register to Ask a Question