I have posted a code last week about that date format problem, well I have figured out a much lesser coding.
#!/usr/bin/bash
clear
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
if [ $# -lt 2 ] ; then
echo " Incorrect Number of Arguments";
echo " Usage : Main_Script <FROM_DATE> <TO_DATE>";
echo " Example : Main_Script 21-JUL-2015 30-JUL-2015";
exit;
fi;
if [ $# == 2 ]; then
if [[ $1 == [0-3][0-9]-[A-Z][A-Z][A-Z]-[0-9][0-9][0-9][0-9] ]]; then
if [[ $2 == [0-3][0-9]-[A-Z][A-Z][A-Z]-[0-9][0-9][0-9][0-9] ]];
then
d1=`date -d $1 +%s`
d2=`date -d $2 +%s`
echo $d1;
echo $d2;
if [[ $d2 -gt $d1 ]];
then
echo "correct";
else
echo "Start date is more than end date";
exit;
fi;
else
echo "Incorrect date format";
echo $2;
echo "Usage : DD-MMM-YYYY";
echo " Example : Main_Script 21-JUL-2015 30-JUL-2015";
exit;
fi;
else
echo "Incorrect date format";
echo $1;
echo "Usage : DD-MMM-YYYY";
echo " Example : Main_Script 21-JUL-2015 30-JUL-2015";
exit;
fi;
fi;
Sample Input : sh date.sh 01-JAN-2015 01-DEC-2014
Sample Output : 1420050600
1417372200
Start date is more than end date
This above stuff is for Linux environment, but when I'm trying to do the same in Solaris it is showing an error as "date -d : illegal format".
Can you help me adjusting some part of this code so that it can run on Solaris as well so that I dont have to install GNU utility package.