Exit 'logread -f' gracefully without ^C

Simple question I can't find answer for.
The logread -f is run in the script.
The operator needs to monitor the messages coming (for undefined time).
When s/he is done, logread -f needs to be exited and script must continue.
Is there any way (key press) to exit logread -f without breaking shell script execution?

Edit: maybe start logread -f in background, get its pid, and check for specific operator action in the script, and then kill the background logread -f using obtained pid when needed...

Look into the trap command for ways to customize the script’s reaction to ctrl-c (INT).

Here’s a primitive example of the script continuing after logread is stopped with Ctrl-C.

#!/bin/sh

trap 'echo "Ctrl-C received"' 2
logread -f

echo "Press enter to exit"
read -r yn
exit

2 represents SIGINT in the trap command.

3 Likes