0

I have a programm which is working in Linux terminal. When it is running the data are outputting into a terminal window, the data are changing every second.

Example of the window:

a b c d

d b c a

c a d b

Data from machine 2 - time: 15:29:31

11 13 17 18 #changing lines

21 18 17 16 #changing lines

18 17 11 9 #changing lines

I'd like to log the data from the window with 10 minutes interval into 1 file. What should be a Bash script, which can read the content of the window, every ten minutes parse it for line 4 and below and append it into 1 file?

Example of desired result - log.txt:

Data from machine 2 - time: 15:40:00

58 47 61 34

17 8 3 2

Data from machine 2 - time: 15:50:00

5 7 8 12

35 41 70 25

33 41 11 14

Data from machine 2 - time: 16:00:00

12 14 15 16

13 18 19 20

24 21 22 23

The second part of this task to my mind could be solved something like this: grep -A 100 "Data from machine " ... | tail -n +2 >> log.txt (don't know what should be instead of ...) But concerning the first part there is more unclear. May be I should see the topic of STDOUT. Need your help.

AntZah
  • 1
  • 1

1 Answers1

0

Well there are a couple of parts of your question both of which are fairly accessible via googling.

part 1...

In order to get the 4th line or 4000th line or whatever line of a file you could follow this discussion: How can I extract a predetermined range of lines from a text file on Unix?

part 2...

Then there is the question of to do it every 10 minutes? You should take your solution from part 1 (whatever you choose to do) and put it in a .sh file and run that script every 10 minutes via crontab, which you access via

crontab -e

And you can read more about that here: https://serverfault.com/questions/248305/running-cron-on-every-10-minutes

Edit part 3 in response to your comment:

Use screen to put your running process in the background and then open another terminal window and do whatever you want in there. You can also connect to the same machine with ssh and have a whole other terminal session running. You don't just have to have 1 terminal session running on 1 screen and nothing else you know. Google nohup or screen.

Community
  • 1
  • 1
  • Thank you for the links. But the problem is that the data must be extracted from the terminal window, not from the text. Running program occupies the terminal, and i can't start any other script or command (sed, awk. grep) in this window. – AntZah Apr 22 '15 at 01:14