Skip to content

Commit 56d8dac

Browse files
authored
Update mysqlmonitor.sh
Added terminal cleanup functionality to ensure proper restoration of the terminal state upon script exit or interruption. Included a trap command to handle SIGINT, SIGTERM, and EXIT signals, invoking the cleanup function on script termination or interruption. Updated the cleanup function to disable line wrapping and restore the terminal screen using tput commands (smcup and rmcup). Modified the script to provide a more graceful exit, including a goodbye message when the script terminates.
1 parent f72c266 commit 56d8dac

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mysqlmonitor.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ if ! output=$(get_mysql_status 2>&1); then
6969
fi
7070
fi
7171

72-
tput smcup 2>/dev/null || true
73-
7472
# Handle CTRL+C and other term signals to restore screen and cursor before exit.
7573
cleanup() {
7674
# Re-enable line wrapping
7775
printf "\033[?7h"
7876
printf '\033[?25h'
79-
tput rmcup 2>/dev/null || true
77+
tput rmcup 2>/dev/null || true
8078
echo -e "\nExiting MySQL Monitor. Goodbye!"
8179
exit
8280
}
8381

84-
trap cleanup SIGINT SIGTERM
82+
trap cleanup SIGINT SIGTERM EXIT
83+
84+
tput smcup 2>/dev/null || true
8585

8686
# Hide the cursor to reduce flicker
8787
printf '\033[?25l'

0 commit comments

Comments
 (0)