My goal:
I would like to redirect the stdout
output of my program foo
to a changing output file depending on the running time of the program.
The program foo
itself is listening on a bsd socket for arriving packets and displays information contained in them.
So essentially, after running the program foo
for 10 minutes, I would like to have the stdout
output of
- the first minute inside the file
bar_0.dat
- the second minute inside the file
bar_1.dat
- …
- the 10th minute inside the file
bar_9.dat
Is it possible to achieve this in a shell script and if yes, how could I accomplish this?
What I have managed so far:
I only managed this solution, where the program is restarted after each minute with the redirection to a new output file:
#!/bin/bash
for i in {0..9}
do
timeout 60s foo > "bar_${i}.dat"
done
However, I want the program foo
to be running continuously and not having to restart it, because in the way I have realized it I am loosing some arriving packets (there is a 20-30ms gap between the running instances).