47 lines
934 B
Bash
Executable File
47 lines
934 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
usage() {
|
|
if [ -n "$1" ];then
|
|
echo -e "\n [ Error ]: $1"
|
|
fi
|
|
|
|
cat<<EOF
|
|
|
|
Usage: $(basename $0) YYY-MM-DD
|
|
|
|
$(basename $0) - Scripts shuts down this machine if the given date is the actual date.
|
|
|
|
The most common practice is, to use this script as cronjob.
|
|
|
|
EOF
|
|
|
|
exit 1
|
|
}
|
|
|
|
[ $# -ne "1" ] && usage "wrong number of arguments"
|
|
|
|
_date=$1
|
|
|
|
IFS='-' read -a _val_arr <<< "$_date"
|
|
|
|
declare -i _year="${_val_arr[0]}"
|
|
declare -i _month="${_val_arr[1]}"
|
|
declare -i _day="${_val_arr[2]}"
|
|
|
|
if [[ $_month -lt 1 ]] || [[ $_month -gt 12 ]]; then
|
|
usage "Wrong date format."
|
|
fi
|
|
|
|
if [[ $_day -lt 1 ]] || [[ $_day -gt 31 ]]; then
|
|
usage "Wrong date format."
|
|
fi
|
|
|
|
if [[ $_year -lt $(date +%Y) ]] ; then
|
|
usage "Wrong date format."
|
|
fi
|
|
|
|
[[ "$(/bin/date +%Y-%m-%d)" == "$_date" ]] && /sbin/poweroff
|
|
#[[ "$(/bin/date +%Y-%m-%d)" == "$_date" ]] && echo "ok: $_date " || echo "failed: $_date"
|
|
|
|
exit 0
|