Help Needed in Date Condition !!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Needed in Date Condition !!
# 8  
Old 03-21-2008
Quote:
Originally Posted by wempy
see this forum entry:

https://www.unix.com/tips-tutorials/3...tion-bash.html

for information and some excellent routines for manipulating dates and times.

Also a read through the man page for date will help you.

a possible solution off the top of my head without testing is:

Code:
while read line; do 
$expires=`echo $line | sed 's/^.*: \(.*\)$/\1'`
$timestamp=`date --utc --date "$expires" +%s`
$nowplus30days=`date --date "now +30 days"`
[ $nowplus30days -lt $timestamp ] && echo $line || echo "Key not in expiring state"
done < a.txt



Thanks for youe help!!

but it giving sed command grabled .. can you please take a look of the below error !! Thanks again


date: illegal option -- -
date: illegal option -- t
date: illegal option -- c
date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
cc.sh[3]: =: not found
date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
cc.sh[4]: =: not found
[expires: 2008-03-29]
sed: command garbled: s/^.*: \(.*\)$/\1
cc.sh[2]: =: not found
date: illegal option -- -
date: illegal option -- t
date: illegal option -- c
date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
cc.sh[3]: =: not found
date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
cc.sh[4]: =: not found
[expires: 2008-04-26]
sed: command garbled: s/^.*: \(.*\)$/\1
cc.sh[2]: =: not found
date: illegal option -- -
date: illegal option -- t
date: illegal option -- c
date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
cc.sh[3]: =: not found
date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
cc.sh[4]: =: not found
[expires: 2008-05-26]
sed: command garbled: s/^.*: \(.*\)$/\1
cc.sh[2]: =: not found
date: illegal option -- -
date: illegal option -- t
date: illegal option -- c
date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
cc.sh[3]: =: not found
date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
cc.sh[4]: =: not found
[expires: 2008-06-26]
sed: command garbled: s/^.*: \(.*\)$/\1
cc.sh[2]: =: not found
date: illegal option -- -
date: illegal option -- t
date: illegal option -- c
date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
cc.sh[3]: =: not found
date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
cc.sh[4]: =: not found
[expires: 2008-07-26]
# 9  
Old 03-21-2008
Hmm, which unix are you using. I came at this from a Linux perspective with GNU Date. If you don't have GNU date then some of those commands will def. fail. Also, as I said, it was off the top of my head, so the sed command regex will probably need some work.

Have to go eat with the inlaws now, so will look at this again tonight if you haven't solved it by then.

Things that might be pertinent:

what unix? (hpux, solaris, tru64 etc)
what version of unix?
do you have access to gnu date?
which shell? (bash, korn etc)
# 10  
Old 03-21-2008
unix version :: SunOS 5.8

Shell type :: Korn
# 11  
Old 03-21-2008
i am not sure of the GNU version of dates here .. i am a new to this platform

i am using sun solaris and Using ksh (Korn shell)
# 12  
Old 03-21-2008
I'm quite new to perl but you can give this a try Smilie

Code:
perl -ane'BEGIN {
  @T = localtime(time+86400*30);
  $t = sprintf "%d-%02d-%02d", ($T[5]+1900),$T[4]+1,$T[3];
}
  chop $F[1]; $t lt $F[1] || print
' file

Of course, fixes and suggestions are welcome!

Last edited by radoulov; 03-22-2008 at 08:38 AM..
# 13  
Old 03-23-2008
Quote:
Originally Posted by radoulov
I'm quite new to perl but you can give this a try Smilie

Code:
perl -ane'BEGIN {
  @T = localtime(time+86400*30);
  $t = sprintf "%d-%02d-%02d", ($T[5]+1900),$T[4]+1,$T[3];
}
  chop $F[1]; $t lt $F[1] || print
' file

Of course, fixes and suggestions are welcome!


Thanks for the reply .. Can you also tell me , when there are no days in the range of 30 days .. it should print " no values are present
# 14  
Old 03-23-2008
You can use something like this:

Code:
perl -ane'BEGIN {
  @T = localtime(time+86400*30);
  $t = sprintf "%d-%02d-%02d", ($T[5]+1900),$T[4]+1,$T[3];
}
chop $F[1]; 
if ($t gt $F[1]) { 
  $c++;
  print; 
}
print "No values present!\n" if (eof and !$c)
' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed with date compare

Hello, I have this unix script which selects rows from DB where current time is greater than expired time (column). So this will give all the records that are expired 1 day ago, 2 days ago, 3 days ago, etc.. I need help modifying in such that it should give records that are only expired 1 day... (5 Replies)
Discussion started by: jakSun8
5 Replies

2. Shell Programming and Scripting

Help needed with some date arithmetic

I have a file (main.lst) containing a list of dates in DDMMYYYY format. The dates will mostly be the same but it is possible to have multiple dates and these need not be in chronological order. I have another file containing another list of dates (holidays.lst). The task is to get the latest... (5 Replies)
Discussion started by: elixir_sinari
5 Replies

3. UNIX for Dummies Questions & Answers

date command option e Help needed please!!

Hi All, I was trying to get the date in format "Feb2" I tried option "e" giving me a padded space and getting the result as "Feb 2". Though its working fine for dates 10 to 31. Please suggest me how to get rid of this space before date. Thanks Olivia (4 Replies)
Discussion started by: Olivia
4 Replies

4. UNIX for Dummies Questions & Answers

Help needed - How to use or condition in makefile

Hi All, i get struck in between how to use OR condition in makefile. Eg: ifeq ($(PACKAGE),x) LIBS += $(STRIPPED_LIB-ONLY) else ifeq ($(PACKAGE),y) LIBS += $(STRIPPED_LIB-ONLY) else LIBS += $(LIB-ONLY) endif endif so if we look into above... (1 Reply)
Discussion started by: dhanavel
1 Replies

5. Shell Programming and Scripting

If(Condition) Rename a file with (Date+Time) Stamp

Hi! Please see our current script: #!/usr/bin/ksh if (egrep "This string is found in the log" /a01/bpm.log) then mailx -s "Error from log" me@email.com, him@email.com </a01/bpm.log fi To the above existing script, we need to add the following change: 1) After finding the string,... (7 Replies)
Discussion started by: atechcorp
7 Replies

6. Shell Programming and Scripting

writing condition using date stamp

Hi all, I am writing a script which i am executing using nohup command. while ( true ) do RequiredTime=06:00:00 SysTime=`echo $(date) | awk '{print $4}'` if ]; then body of script fi done this is executing 3 times at 6am. i want it execute the body of script... (3 Replies)
Discussion started by: firestar
3 Replies

7. Shell Programming and Scripting

Help needed-calculate previous date

Hi Friends, Need a command/script in unix which calculates previous date from current date. For ex: If current date= 01 Jan 2008, then output =31 Dec 2007 If current_date =01 Aug 2008 , then output= 31 July 2008 Please advice Regards, Suresh (3 Replies)
Discussion started by: sureshg_sampat
3 Replies

8. UNIX for Dummies Questions & Answers

Help needed with date

How can i assign a variable by the name of CUTDATE= today date - 90 days? i have something like this right now :- today=`date '+%Y%m%d'` #cutdate = this is where i am having problem. i need today - 90 days How can i accomplish this? After that i need to do delete the data which are more... (16 Replies)
Discussion started by: chris1234
16 Replies

9. Shell Programming and Scripting

help needed in date format

i need to grep date in the format year-month-day,,,,,,, actually i need to grep those dates other than current date.......... can anyone help me in this...........i need a format of date which would grep previous date except current date (1 Reply)
Discussion started by: ali560045
1 Replies

10. Shell Programming and Scripting

Help needed on Date command

Hi, I am facing one problem with date command.Actually I want to use this command to get the last month,not the current month..OK,I can do current month - 1 and give special condition for january,But this time i need last month as strings like January,februaury,march etc... There is option... (5 Replies)
Discussion started by: nikunj
5 Replies
Login or Register to Ask a Question