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;

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.