From 1836f0493877159bc2c0551567875d71e73e63e4 Mon Sep 17 00:00:00 2001 From: Nicolas Roman Date: Fri, 15 Feb 2019 15:34:19 +0100 Subject: [PATCH] added timeout on read function --- evomaintenance.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/evomaintenance.sh b/evomaintenance.sh index 1d22d71..b576e7f 100755 --- a/evomaintenance.sh +++ b/evomaintenance.sh @@ -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 to submit, or to cancel." -read enter +timedout_read enter # write log echo "----------- $(get_now) ---------------" >> "${LOGFILE}"