the below script is to get & check the correct values for minutes (0-59) that is inputed by user :
printf "$FBOLD\nPlease enter the minutes (0-59): $FREG"
read MIN
case "$MIN" in
[0-9]|[0-5][0-9]) break 2;;
*)
echo ""
echo "Invalid minutes, please try again.";;
esac
How to give the same range for day of month (1-31) and for month (1-12) and hour (0-23) ???
Also, after getting user input, how to get it displayed as below :
Cronjob scheduled on "month day_of_month day_of_week hour minute "
Hi, I think You can let the date command do the work for You. If it's a valid date, it will echo the "Cronjob... " line, if it's an invalid date, You will get an error, like
Like this:
echo -n Please enter MONTH DAY HOUR MINUTE :
read MONTH DAY HOUR MINUTE
date -d"$(date -d+%Y)${MONTH}${DAY} ${HOUR}:${MINUTE}" > /dev/null && echo "Cronjob scheduled on $MONTH $DAY $HOUR $MINUTE"
But maybe You would wish to do something more than just echo the text, then create a block of code. And You may have to adjust for the date and time format used in Your LOCALE.