I'm currently redirecting the output of a monitoring tool to a file, however what I'd like to do, is to redirect this output to a new file on my request (using a keybinding), without stopping the said tool.
Something like
monitor_program | handle_stdout Where handle_stdout allows me to define a new file where to put the log at certain point.
I know I could easily write it, but I'm wondering if there's any tool that already allows this.
EDIT
Thanks to Jeff Schaller's answer, I ended up with something like this, which basically does what I need, let's call it reader.sh:
#!/bin/sh INDEX=0 LOGNAME="$INDEX.log" switchlog() { local custom_name read -p "Add log name: " custom_name INDEX=$((INDEX+1)) LOGNAME="$(printf "%03d" $INDEX).$custom_name.log" echo now writing to $LOGNAME } trap switchlog INT switchlog while : do read foo < p printf "%s\n" "$foo" >> "$LOGNAME" done Then it's just about creating a named pipe with mkfifo p, and using two terminals where monitor_program > p and reader.sh are running. I can then stop the reader to set a new log by using Ctrl+C, and enter a new name. Ctrl+Z, as usual then to stop and kill it.