I'm searching for compare two date in AIX. This is the first date in yyyyMM format:
three_months_ago=$(( $(date +%Y%m) - 3))
And I get the second date from filesystem with concatenation of folder name:
for dir in /p22_satos/satos/data/*
do
echo ${dir}
year=$(basename ${dir})
if [[ $dir = "/p22_satos/satos/data/static" ]];
then
print "Static dir should not be deleted"
else
for subdir in ${dir}/*
do
echo ${subdir}
month=$(basename ${subdir})
if [ $month -ge 10 ];
then
echo ${year}${month}
echo $three_months_ago
if [ ${year}${month} -ge $three_months_ago ];
then
echo "The directory should not be deleted"
else
echo "The directory should be deleted"
fi
else
echo ${year}"0"${month}
echo $three_months_ago
if [ ${year}"0"${month} -ge $three_months_ago ];
then
echo "The directory should not be deleted"
else
echo "The directory should be deleted"
fi
fi
#rm -f $subdir
done
fi
The value for $three_months_ago is 202103. I've folder 2020 with subfolder 12, so the cycle make 202012 date dynamically.
Why ${year}${month} and ${year}"0"${month} are always greater than $three_months_ago and the if [ ${year}${month} -ge $three_months_ago ] fails?
Aucun commentaire:
Enregistrer un commentaire