diff --git a/evomaintenance.sh b/evomaintenance.sh index 1d22d71..4db0a98 100755 --- a/evomaintenance.sh +++ b/evomaintenance.sh @@ -63,6 +63,20 @@ 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 + # maximum allowed by stty + export TMOUT=25 + fi + user_input=$1 + old_tty_settings=$(stty -g) + stty -icanon min 0 time ${TMOUT}0 + read -r "$user_input" + stty "$old_tty_settings" + unset TMOUT +} + test -f /etc/evomaintenance.cf && . /etc/evomaintenance.cf [ -n "${HOSTNAME}" ] || HOSTNAME=$(get_fqdn) @@ -123,7 +137,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 +159,7 @@ echo "" echo "${BLOB}" echo "" echo "> Press to submit, or to cancel." -read enter +timedout_read enter # write log echo "----------- $(get_now) ---------------" >> "${LOGFILE}" @@ -185,7 +199,16 @@ fi SQL_TEXTE=`echo "${TEXTE}" | sed "s/'/''/g"` PG_QUERY="INSERT INTO evomaint(hostname,userid,ipaddress,begin_date,end_date,details) VALUES ('${HOSTNAME}','${USER}','${IP}','${BEGIN_DATE}',now(),'${SQL_TEXTE}')" -echo "${PG_QUERY}" | psql ${PGDB} ${PGTABLE} -h ${PGHOST} +#echo "${PG_QUERY}" | psql ${PGDB} ${PGTABLE} -h ${PGHOST} + +curl -H "Content-Type: application/json" -X POST http://172.28.128.3:8000 -d '{ + "hostname": '${HOSTNAME}', + "userid": '${USER}', + "ipaddress": '${IP}', + "begin_date": '${BEGIN_DATE}', + "end_date": '$(now())', + "details": '${SQL_TEXTE}' +}' # send mail MAIL_TEXTE=$(echo "${TEXTE}" | sed -e "s@/@\\\\\/@g ; s@&@\\\\&@")