Comparing Output Date to Current System Date


 
Thread Tools Search this Thread
# 1  
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:
Code:
Command was launched from partition 0.


------------------------------------------------
Executing command in server server6
Fri Dec 16 13:56:44 EET 2011


------------------------------------------------
Executing command in server server3
Fri Dec 16 13:56:44 EET 2011


------------------------------------------------
Executing command in server backup-server
Fri Dec 16 13:56:44 EET 2011


------------------------------------------------
Executing command in server server1
Fri Dec 16 13:56:45 EET 2011


------------------------------------------------
Executing command in server server9
Fri Dec 16 13:56:45 EET 2011

What I want to do is to check even just the DAY DATE HH:MM of the results versus the current system date/time.

Please advice,
rymnd_12345
# 2  
bash code:
  1. #! /bin/bash
  2.  
  3. curr=`date +"%a %b %d %H:%M"`
  4. while read x
  5. do
  6.     echo $x | egrep -q "^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) "
  7.     [ $? -ne 0 ] && continue || dt=`echo $x | cut -c1-16`
  8.     [ "$curr" == "$dt" ] && echo "Date time in \"$x\" matches with current date time"
  9. done < input

Last edited by balajesuri; 12-16-2011 at 09:27 AM..
# 3  
Hi balajesuri,

Thanks, I've tried to ran the script but I got no output.


Please advice,
rymnd_12345
# 4  
Another idea. Bear in mind that because your match includes HH:MM your file needs to be totally up-to-date to get a match. I've assumed that the original log file entries came from the "date" command with no parameters.

Code:
today="`date|cut -c1-16`"
grep "${today}" abc161.txt 2>&1 >/dev/null ; reply=$?
if [ $reply -eq 0 ]
then
        echo "File contains: ${today}"
fi

# 5  
Hi methyl,

I've tried to ran the script, but still no output was produced. Please see below my file and code:

File:
Code:
Command was launched from partition 0.


------------------------------------------------
Executing command in server server6
Fri Dec 16 16:38:26 EET 2011


------------------------------------------------
Executing command in server server3
Fri Dec 16 16:38:26 EET 2011


------------------------------------------------
Executing command in server backup-server
Fri Dec 16 16:38:26 EET 2011


------------------------------------------------
Executing command in server server1
Fri Dec 16 16:38:26 EET 2011


------------------------------------------------
Executing command in server server9
Fri Dec 16 16:38:26 EET 2011

Code:
Code:
#!/usr/bin/sh

today="`date|cut -c1-16`"
grep "${today}" /home/subdirectory/today-file 2>&1 >/dev/null ; reply=$?
if [ $reply -eq 0 ]
then
        echo "File contains: ${today}"
fi


Br,
rymnd_12345
# 6  
The script will only have produced output if the time at the time the script was run was:
Code:
Fri Dec 16 16:38

Have we misunderstood your requirement from Post #1 ?
Quote:
What I want to do is to check even just the DAY DATE HH:MM of the results versus the current system date/time
# 7  
Or said another way: what are you trying to do exactly - please do not explain with your example.

A good answer might be: I'm trying to see if a log file shows that the process is still running. That appears to me to be what you are doing, by the way.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Computers
Difficulty: Medium
To bypass US Munitions Export Laws, the creator of the PGP published all the source code in book form.
True or False?

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

3. Shell Programming and Scripting

Comparing the dates with the current date in perl scripting

Hi i have a file containg dates likebelow 4/30/2013 3/31/2013 4/30/2013 4/16/2013 4/30/2013 4/30/2013 5/30/2013 5/30/2013 4/30/2013 5/30/2013 5/30/2013 3/31/2013 now i want to compare the above dates with current date and i want to display the difference . (10 Replies)
Discussion started by: siva kumar
10 Replies

4. UNIX for Dummies Questions & Answers

Comparing two files with datestamp to current date

Hi, I am new to unix and I am stuck on how to compare two .zip file with date stamp in my directory. I need to compare out of the two file which is oldest to current date and unzip it after that done continue to unzip the second zip file. Thanks for your help. (5 Replies)
Discussion started by: lilvi3tboix1
5 Replies

5. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

6. Shell Programming and Scripting

Comparing current date

Hi, I have start date and end date in the following format. I need to check the current date is greater than the start date and less than the end date. if i use the command date --date "Tue 6:00 AM", it takes next Tues day not the current week's Tues day. Is there a way to get the current Tues... (9 Replies)
Discussion started by: bharathappriyan
9 Replies

7. Shell Programming and Scripting

how to get what date was 28 days ago of the current system date IN UNIX

Hi, Anybody knows how to get what date was 28 days ago of the current system date through UNIX script. Ex : - If today is 28th Mar 2010 then I have to delete the files which arrived on 1st Mar 2010, (15 Replies)
Discussion started by: kandi.reddy
15 Replies

8. UNIX for Dummies Questions & Answers

get current system date

How do I create a shell script that would get the current system date in format of yyyymmdd and use that result to concatenate it to a filename that it would look like this: sample20051024.dat example -------- current system date: 24-Oct-2005 filename: sample.dat when the shell script... (5 Replies)
Discussion started by: wtolentino
5 Replies

9. 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

10. UNIX for Dummies Questions & Answers

I want to get day from the current system date

Hi, I want to check what day is today (like mon,Tue,wed) When i checked the syntax, i dont see there is a format specifier for getting the day. Let me know how to get the same. I am very new to unix and so I am asking some basic questions. cheers, gops (2 Replies)
Discussion started by: gopskrish
2 Replies

Featured Tech Videos