Redirecionando / grep'DO STDOUT de um shell existente

3

Eu executo muitos processos de longa duração (simulações) que imprimem o progresso para STDOUT . Ocasionalmente me esqueço de redirecionar para STDOUT para um arquivo que eu posso grep , e geralmente é muito tempo para reiniciar.

PERGUNTA: Sem interromper o processo, existe uma maneira que eu possa ligar para outro STDOUT ?

Eles estão sempre rodando na tela GNU com o ZSH no OS X 10.7.3.

    
por jmdeldin 23.03.2012 / 05:32

2 respostas

4

Existe um hack inteligente citado aqui que usa o GDB para anexar ao processo, e um utilitário chamado dupx finaliza essa funcionalidade.

Na página de manual dupx :

Dupx is a simple utility to remap files of an already running program. Shells like Bash allow easy input/output/error redirection at the time the program is started using >, < - like syntax, e.g.: echo 'redirect this text' > /tmp/stdout will redirect output of echo to /tmp/stdout.

Standard shells however do not provide the capability of remapping (redirecting) of output (or input, or error) for an already started process. Dupx tries to address this problem by using dup(2) system call from inside gdb(1). Dupx is currently implemented as a simple shell wrapper around a gdb script.

    
por 23.03.2012 / 06:26
0

Use o comando log da tela (!)

Como o processo está sendo executado em uma sessão de tela, é apenas uma questão de dizer à tela para registrar a saída dessa janela:

Mude para a janela do script, C-a H para registrar.
Agora você pode:

$ tail -f screenlog.2 | grep whatever

Da página de manual da tela:

log [on|off]

Start/stop writing output of the current window to a file "screenlog.n" in the window's default directory, where n is the number of the current window. This filename can be changed with the 'logfile' command. If no parameter is given, the state of logging is toggled. The session log is appended to the previous contents of the file if it already exists. The current contents and the contents of the scrollback history are not included in the session log. Default is 'off'.

    
por 06.05.2016 / 04:22