I have developed a script which will compare two dates.
#!/bin/ksh
####################################################################
#
#DECLARING ALL THE VALUES AND PATHS
#
####################################################################
LOG_FOLDER=/user/sba-appl/test/sscr/ramu
TARGET_DIR=/user/sba-appl/test/sscr/ramu
###################################################################
#
#GETTING THE TIME STAMP OF THE FILE
#
####################################################################
cd $TARGET_DIR
DEFAULT_DATE=`ls -l /$TARGET_DIR/default.txt| awk '{print $6,$7,$8}'`
printf "$DEFAULT_DATE \n"
for f in *.xml
do
echo "Processing $f"
FILE_DATE=`ls -l /$TARGET_DIR/$f|awk '{print $6,$7,$8}'`
printf "$FILE_DATE \n"
echo "dafault filedate is $DEFAULT_DATE"
if [ $FILE_DATE -gt $DEFAULT_DATE ]
then
echo "Call the Jar for the file $f"
else
echo "Do not call the Jar for the file $f"
fi
done
Here I'm facing two problems:
1. In this we have a default file and this file timestamp should be set to old time ie for eg 1990. I know this can be done with the help of touch -t
with the timestamp.
I am using a ksh and stat is not present here. So I'm using ls -l
. But if i am using ls -l
command then it will list the year 1990 (because it will always list the year if the file is 6 months older). In this case my default_date value will have year.
So I think my if condition is failing as year is coming here.
2. I changed the timestamp of the files including default.txt
within 6 months and I checked now but still it is not executing the if part and it is executing the else part.
I'm also getting unknown test operator. Can anyone tell me where it is going wrong. It will be great help if anyone can check this.
I am facing two problems here:
- In this comparison the if condition is not correctly working.
- Always it is printing the else part only.
stat
? if it's AIX, check if you haveistat
.