The main answer:
case "$1" in
(-force)
: OK;;
(*)
case $(date +'%H') in
(09|1[0-6])
echo "Cannot run between 09:00 and 17:00" 1>&2
exit 1;;
esac;;
esac
Note that I checked this (a script called "so.sh") by doing:
TZ=US/Pacific sh so.sh
TZ=US/Central sh so.sh
He worked in Pacific time (08:50), and not in central time (10:50). The point here is that your controls are as good as your environment variables. And users can futz with environment variables.
source
share