I have written a code in Linux environment which compares two dates and print "correct" if 1st date is less than 2nd date. But when I'm running the same code in SunOS environment, "date -d is an illegal format" is the error it is throwing. How different should my code be so that it executes well in SunOS environment.
#!/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;
It would be of great help if someone can help me.
Thank you