WIP: Added timeout on read function #6
|
@ -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}"
|
||||
|
|
Loading…
Reference in a new issue
10:2: note: read without -r will mangle backslashes. [SC2162]
10:7: note: Double quote to prevent globbing and word splitting. [SC2086]
Strange that it didn't erase the review automatically.