added timeout on read function

This commit is contained in:
Nicolas Roman 2019-02-15 15:34:19 +01:00
parent 0621f62267
commit 1836f04938

View file

@ -63,6 +63,19 @@ get_now() {
date +"%Y-%m-%dT%H:%M:%S%z"
}
# timeout on read(), uses TMOUT env as timer
timedout_read() {
if [ -z ${TMOUT+x} ] || [ "$TMOUT" = 0 ]; then
export TMOUT=36000
fi
user_input=$1
old_tty_settings=$(stty -g)
stty -icanon min 0 time ${TMOUT}0
read $user_input
stty "$old_tty_settings"
unset TMOUT
}
test -f /etc/evomaintenance.cf && . /etc/evomaintenance.cf
[ -n "${HOSTNAME}" ] || HOSTNAME=$(get_fqdn)
@ -123,7 +136,7 @@ fi
# get input from stdin
echo "> Please, enter details about your maintenance"
read TEXTE
timedout_read TEXTE
if [ "${TEXTE}" = "" ]; then
echo "no value..."
@ -145,7 +158,7 @@ echo ""
echo "${BLOB}"
echo ""
echo "> Press <Enter> to submit, or <Ctrl+c> to cancel."
read enter
timedout_read enter
# write log
echo "----------- $(get_now) ---------------" >> "${LOGFILE}"