User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 428,224 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,248 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 20619 | Replies: 3
Reply
Join Date: Oct 2005
Posts: 6
Reputation: pichels is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pichels pichels is offline Offline
Newbie Poster

Script to compare dates?

  #1  
Oct 28th, 2005
Hi,

I have created a convaluted and hacked script here for comparing unix dates.

Can someone help me use calc or date w/ julian param or something to look back a week, a month or even a year and compare dates or add/subtract the dates somehow in a shell script?

Hope this makes sense!
Thanks for any help or resources.

My script( I apologize if this example doesn't work right, I have been changing it and trying to make sense of it!):

#!/bin/bash

#Day of the week
DAT="`date +%w`"

#Current date
CDAT=`date +%Y-%m-%d | sed 's/-//g' | cut -c5-8 | sed 's/^0//'`


# Get DATETIME in this format: "2005-10-16 20:03:36" from IBM TSM Database - DB2
dsmadmc -id=admin -password=admin select 'DATE(LAST_WRITE_DATE)','TIME(LAST_WRITE_DATE)' from volumes where STGPOOL_NAME="'LTOPOOL2'" | grep -v -e IBM -e Copyright -e Tiv -e Comm -e Sess -e Serv -e ANS -e Vol -e VOL -e "---" -e LAST -e Unnamed | /bin/sed '/ *#/d; /^ *$/d' > $DATETIME





cat $DATETIME | awk '{ print $1; }' > $DBDATE


cat $DBDATE | cut -c6-10 | sed 's/-//g' | sed 's/^0//' | sort -u | uniq > $STRIPDATE
cat $DBDATE | cut -c6-10 | uniq > $DAYMONTH




for NUM in `cat $STRIPDATE`
do



if [[ `expr $CDAT - $NUM` = 22 || `expr $CDAT - $NUM` > 90 ]]
then


echo $NUM | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{2\}\)/\1-\2/;ta' >> $GETDAYMONTH


else

:

fi


done




cat $GETDAYMONTH | uniq >> $CALCDAYMONTH




for CNUM in `cat CALCDAYMONTH`
do

grep "$CNUM" $DATETIME | sed 's/ //' >> $ARCHHOLD


done


cat $ARCHHOLD | sed -e 's/./& /10' > $FINAL_ARCH


done


exit 0;
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2004
Posts: 177
Reputation: jim mcnamara is on a distinguished road 
Rep Power: 5
Solved Threads: 9
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: Script to compare dates?

  #2  
Nov 15th, 2005
Date arithmetic in shell is a pain. This link gives you several good scripts that do date compares and date arithmetic:

http://www.unix.com/showthread.php?t=13785
Reply With Quote  
Join Date: Oct 2005
Posts: 6
Reputation: pichels is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pichels pichels is offline Offline
Newbie Poster

Re: Script to compare dates?

  #3  
Nov 15th, 2005
Originally Posted by jim mcnamara
Date arithmetic in shell is a pain. This link gives you several good scripts that do date compares and date arithmetic:

http://www.unix.com/showthread.php?t=13785

Great link, thanks Jim!
Reply With Quote  
Join Date: Jun 2007
Posts: 1
Reputation: dsmall is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dsmall dsmall is offline Offline
Newbie Poster

Re: Script to compare dates?

  #4  
Jun 13th, 2007
i'm trying to create a script that compares today's date with the date of some files that have been ftp'd over earlier in the day. basically, i want to ensure that today's date and the file's date match.

before i head off down this path, i just want to make sure that i'm not reinventing the wheel.

thanks,
doug
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 3:30 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC