I have searched all over but the option to display the date format in SunOS 5.10 is present, but no answers for how to check the valid format as per our requirements.
#!/bin/bash
date +'%Y%m%d' -d "$4" 2>&1 >> ${LOG_FILE}
is_valid=$?
if [ $is_valid -eq 1 ];then
echo "Invalid date format"
exit 2
fi
When I execute the command I pass the date in the option and if the date format is not correct the shell should exit. This format check command is not working in SunOS.
I don't think the SunOS 5.10 version of
dateaccepts the-doption. However, it does provide thecalcommand. As your date format is all digits, it is quite easy to split into year, month and day, feed the month and year intocaland then usegrepto look for the day. Something like:Note: Untested, as I no longer have any Solaris 10 machines.