While read pipe input issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While read pipe input issue
# 1  
Old 09-10-2017
While read pipe input issue

Hello,
I have an ffmpeg bash script which is working nice and
I need to do the same for other sources.
To create new scripts and to deal with multiple bash files sounds not logical. It is a bit hard to manage for me..
I wondered if it was possible to make my input file as variable.
Then I wrote below scripts to make it shorter


This one works as expected.
working_nice_one.sh
Code:
#!/bin/bash

while read line
do

/usr/bin/ffmpeg -loglevel quiet -re -y -reconnect_delay_max 2 -timeout 1600000 \
-i $line -c copy -f mpegts pipe:1 </dev/null

done < myfile

myfile
Code:
http://xx.yy.zz
http://aa.bb.cc
http://11.22.33

I call the script this way: (this is what I do not prefer)
Code:
pipe:///home/working_nice_one.sh

When the first source goes down, it runs the second source promptly, etc..
At the end of the loop, it goes back to first url line once again. That is good..

Below one is working just for the first line of myfile source. Not looping for some reason. I really dont understand why this is happening.


it_works_but_not_loop.sh
Code:
#!/bin/bash

while read line
do

/usr/bin/ffmpeg -loglevel quiet -re -y -reconnect_delay_max 2 -timeout 1600000 \
-i $line -c copy -f mpegts pipe:1 </dev/null

done < "$1"


I call the script this way: (what I wish to accomplish)
Code:
pipe:///home/it_works_but_not_loop.sh myfile


Could you please explain why the second one is not looping and reading only the first line of my source file? I am scratching my hairs

Thanks
Boris
# 2  
Old 09-10-2017
Perhaps you might be able to know what's going on by asking for a little bit of debugging feed back, setting the flag x
Code:
#!/bin/bash


set -xv # try this

while read line
do

/usr/bin/ffmpeg -loglevel quiet -re -y -reconnect_delay_max 2 -timeout 1600000 \
-i $line -c copy -f mpegts pipe:1 </dev/null

done < "$1"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help on passing an input variable to the voronota program (after third pipe)

Dear UNIX forum members, I am using macbook pro 13 (2015 edition) with MAC OS Mojave and am trying to write the shell script where when it is run through terminal it asks for an input (in the code below an input variable is domains) and then that input becomes capital letter or letters which... (3 Replies)
Discussion started by: Aurimas
3 Replies

2. Shell Programming and Scripting

Space in input filename with pipe

Hello, Normally below script works, could you please comment out what could be the reason of failure if there are spaces in input filename: script.sh #!/bin/bash cd /home/hts/.hts/tvh/ file="$1 $2 $3 $4" read -d $'\x04' name < "$file" /usr/bin/ffmpeg -i ""$name"" -vcodec copy -preset... (1 Reply)
Discussion started by: baris35
1 Replies

3. Shell Programming and Scripting

Read input from Keyboard, do not proceed if no input

Hi, I am working on a script, which requests users to enter input. Ex: read -p "Please enter your email id:" email I don't want users skipping this entry, this has to be mandatory.I dont want to proceed without input. I can do a check if variable $email is empty and proceed if not.But, i... (7 Replies)
Discussion started by: aravindadla
7 Replies

4. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

5. Shell Programming and Scripting

Read pipe data

Hello, I need to read the pipe data as:- cat abc.txt | uuencode abc.txt | mailx -s hi xyz@xyz.com I will override the mailx function so that when mailx is called, it calls my version of maix and in that function I want to read the file which is attached in progional mailx function- abc.txt... (7 Replies)
Discussion started by: shubh05
7 Replies

6. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

7. Shell Programming and Scripting

How to use an input pipe ?

Hi all, I would like to use properly an input pipe, like this : cat myFile.txt | myCommand.shI always find this solution : while read line; do ...; donebut I have a great lost of performance ! On a big file, with a simple grep, I can spend 2400 times more time ! oO (from 0,023sec to 1m)... (4 Replies)
Discussion started by: LeNouveau
4 Replies

8. Shell Programming and Scripting

Read from a pipe or die in perl

I have a perl program that I want to read from a file passed as an argument or from a pipe. If their is no pipe or arguments, I want it to output a help message. I am stuck on how to prevent perl from reading from the keyboard if it isn't fed any file names or data from a pipe. The only things I... (4 Replies)
Discussion started by: ilikecows
4 Replies

9. UNIX for Dummies Questions & Answers

Standard error output to Pipe input - solved

Hi, I want to check a particular word is in standard error output or not. Can I acheive it in single command? For example, Delete file_name 2>error.log cat error.log Output: XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX Successfully deleted XXXXXXXXXXXXXXXXX where delete is... (2 Replies)
Discussion started by: poova
2 Replies

10. Programming

Problem in read() from a pipe

Hi, Can any one please help me with this. Am struggling hard to get a solution. I am doing telnet through a C program and getting the stdout file descriptor of the remote machine to pipe. read() function is getting data, But whenl it receives SOH character ie. ^A ( Start of heading = Console... (2 Replies)
Discussion started by: JDS
2 Replies
Login or Register to Ask a Question