Skip to main content
Tweeted twitter.com/StackUnix/status/728158730940993536
Rollback to Revision 2
Source Link
Braiam
  • 36.9k
  • 29
  • 114
  • 176

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.

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.

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.

added 4 characters in body
Source Link

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).$logname$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.

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).$logname.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.

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.

added 13 characters in body
Source Link

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="$INDEXLOGNAME="$(printf "%03d" $INDEX).$custom_name$logname.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.

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="$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.

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).$logname.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.

Added accepted answer
Source Link
Loading
added 21 characters in body
Source Link
Loading
Source Link
Loading