G
G
glaucidium2019-03-31 14:45:49
bash
glaucidium, 2019-03-31 14:45:49

How to make realtime log in terminal?

It is necessary that the working script spin and log messages to a predetermined place, and in another terminal they would be displayed as they arrive.
Considered solutions:
• Immediately write to the logging terminal. The problem is that terminal numbers are created dynamically and you don't want to correct the main script every time you start it. • Write to a file. Then you have to write a viewing program with an infinite loop, tracking the difference, doing. I think it's fat for such a task. • Pee into a pipe.
echo$message” > /dev/tty2

tty1:   ping toster.ru > pipe
tty2:   cat pipe

Exactly what is needed! But the pipe will block the main script if no one reads it.
Is it possible to somehow know if a pipe is full before writing into it?
Or is there some standard solution?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xotkot, 2019-03-31
@glaucidium

• Write to a file.
Then you have to write a viewing program with an infinite loop, tracking the difference, doing. I think it's fat for such a task.

it is also possible as an option:
mkfifo fileFIFO #создать файл(именованный канал) fifo
exec 4<>fileFIFO #открыть дескриптор файла на чтение/запись
echo Test1 >&4
...
echo TestN >&4
exec 4>&- #закрыть

read(from opening to closing):
cat fileFIFO

M
moropsk, 2019-03-31
@moropsk

lnav

A
andgera, 2019-04-01
@andgera

terminal program launch, script
$ ping 8.8.8.8 | logger -t mycmd
any other terminal
$ journalctl -ft mycmd

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question