2

I write a bash script that run some other commands in new terminal:

#!/bin/bash
# Sample script
gnome-terminal --title="blah blah" -x bash -c ffmpeg -i udp://239.1.2.1:60001?fifo_size=50000000 -acodec copy -vcodec copy -preset ultrafast \
-flags -global_header -f hls -hls_time 20 -hls_wrap 5 /var/www/html/ts/1.m3u8 &

sleep 1

gnome-terminal --title="blah blah" -x bash -c ffmpeg -i udp://239.1.2.2:60002?fifo_size=50000000 -acodec copy -vcodec copy -preset ultrafast \
-flags -global_header -f hls -hls_time 20 -hls_wrap 5 /var/www/html/ts/2.m3u8

The output of each ffmpeg line is more than one page and it is similar to:

libavutil      54.  7.100 / 54.  7.100
  libavcodec     56.  1.100 / 56.  1.100
  libavformat    56.  4.101 / 56.  4.101

  ... many pages after ....

[h264 @ 0xc04c60] decode_slice_header error
[h264 @ 0xc04c60] no frame!
[h264 @ 0xc04c60] non-existing PPS 0 referenced

.... many pages after .... 

  Program 105 
    Metadata:
      service_name    : IRIB-TV5
      service_provider: IRIB
[adts @ 0xf943e0] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
Output #0, hls, to '/home/stream/Desktop/tst/1.m3u8':
  Metadata:
    encoder         : Lavf56.4.101
    Stream #0:0: Video: h264 (libx264), yuv420p, 720x576 [SAR 12:11 DAR 15:11], q=-1--1, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.1.100 libx264
    Stream #0:1(per): Audio: aac, 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc56.1.100 aac
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac_latm (native) -> aac (native))
Press [q] to stop, [?] for help
[h264 @ 0xf42120] reference picture missing during reorder
[h264 @ 0xf42120] Missing reference picture, default is 65716
[h264 @ 0xf42120] reference picture missing during reorder
[h264 @ 0xf42120] Missing reference picture, default is 65717

When I run this script in a new terminal and I launch the command (in this case ffmpeg), it immediately shows many output lines, many pages sometimes, and goes to last message automatically...

How can I scroll up and down to first message in the terminal, or stop it at the first page?

  • Ok now this is another question. Use | more or | less to stop the output after the first page (then you need to press enter... Example gnome-terminal --title="blah blah" -x bash -c ' find ~ | less' – Hastur Mar 24 '16 at 17:07
  • and what i must do for go to last page? – Ali Mar 24 '16 at 17:12
  • See below the update answer or search on your computer with man less or man more. – Hastur Mar 24 '16 at 17:17
  • Perfect...tnx a lot – Ali Mar 24 '16 at 17:19
  • You're welcome. I tried to make more clear your text. Feel you free to edit again or to "rollback" the modifications. Btw the first message is the more hidden in the terminal (more up), not the last one: for this it was difficult to understand you... :-) ps> Welcome on SuperUser. – Hastur Mar 24 '16 at 17:32
1

Update after that the question was completely reformulated:

You can use | more or | less to stop the output after the first page.

 gnome-terminal --title="blah blah" -x bash -c  ' find  ~  | less'

Note: you need to use '' to say where it finishes the bash commands.
Within less you can move:

  • Home and End To the beginning and the end of the page.
  • PgUp and PgUp One page down or up.
  • Up and Dn One line up or down.

One of the line of your script can be similar to

gnome-terminal --title="blah blah" -x bash -c                                 \
'ffmpeg -i udp://239.1.2.1:60001?fifo_size=50000000 -acodec copy -vcodec copy \
-preset ultrafast -flags -global_header -f hls -hls_time 20 -hls_wrap 5       \
/var/www/html/ts/1.m3u8 | less ' &

There are some shortcuts:

  • Ctrl+ Shift+Up or Dn To scroll up or down of a line
  • Shift+PgUpor PgDn To scroll up or down of a page
  • Shift+Home or End To scroll up to the beginning or down to the end

You can read about other shortcuts directly on the gnome help page.

  • But i want to do that in bash , for example in the end of my coomand...is it possible? – Ali Mar 24 '16 at 13:21
  • I misunderstood it (nice version of you may be more clear ;-) ): add a | less or | more to your command. Example tree . | less. BTW this redirect the stdout. If you want to redirect even the stderr you have to write explicitly. (Example tree . 2>&1 | less ). Does it solve your problem? – Hastur Mar 24 '16 at 13:22
  • I use dvblast (a program for live tv streaming) ...i start dvblast 10 times for 10 channels...when i start dvblast it show many massages in terminal and i want to see last message ...i run dvblast with the code that i said in question and i want to do that in that code – Ali Mar 24 '16 at 13:35
  • 1
    @combo_ci My dear it is the 3rd time you change your question... now you are asking a different question (and a specific one). Take some moment to read How to Ask. It will help you to have the answer you need and the others to avoid to waste time answering to an unneeded question. Nothing personal. BTW do another question adding a typical output, the desired output and the information if you run all the 10 dvblast from the same shell... – Hastur Mar 24 '16 at 13:41
  • Tnx for reply but i think my question is clear ... I run terminam from bash...output of terminal is too line that not show in one pge....i want to force terminal to scoll down to last message ...just it – Ali Mar 24 '16 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.