2

Environment

Linux version 2.6
Screen version 4.03.01

I am running an application inside of a screen session. The program prints to STDOUT and reads from STDIN.

What I would like to do:

First, have STDOUT of the screen tee'd to a file. For some reason, piping to tee only writes the first few lines, then stops. This maybe because the shell script I am executing runs other applications/shell scripts... Is there a way to connect to the STDOUT of the screen session?

Second, I would like to create a file, like a fifo maybe?, that I can write data do and have it send that data to the STDIN of the screen session.

I am open to other suggestions, such as not using screen at all and doing something with nohup and some fifo's

Basically, I want to background an application and have a file that I can tail for the output and another to redirect input to.

Tim
  • 200

1 Answers1

3

Basically, I want to background an application and have a file that I can tail for the output and another to redirect input to.

If that is the case, then (1) we need to background application and send its output to file file:

application >file &

And, (2) we need to tail application's output to command another:

tail -f | another

Example

Let's create a sample application and another:

$ application() { while sleep 1; do date; done; }
$ another() { grep 2017; }

Now, let's start application in the background:

$ application >file &
[1] 5989

And, let's run another in the foreground:

$ tail -f file | another
Sat May 20 18:32:05 PDT 2017
Sat May 20 18:32:06 PDT 2017
Sat May 20 18:32:07 PDT 2017
Sat May 20 18:32:08 PDT 2017
Sat May 20 18:32:09 PDT 2017
Sat May 20 18:32:10 PDT 2017
[...clip...]

Inside a screen session using a FIFO

First, start a screen session. Then run:

$ mkfifo fifo
$ application >fifo &
[1] 8129
$ cat fifo | another
Sat May 20 18:50:39 PDT 2017
Sat May 20 18:50:40 PDT 2017
Sat May 20 18:50:41 PDT 2017
Sat May 20 18:50:42 PDT 2017
Sat May 20 18:50:43 PDT 2017
Sat May 20 18:50:44 PDT 2017
Sat May 20 18:50:45 PDT 2017
Sat May 20 18:50:46 PDT 2017
[...snip...]

(I used cat fifo | another for its parallism to the first tail -f version. cat is unnecessary here. We could have used another <fifo.)

John1024
  • 17,343