SOLVED: trying to wrap long command
I'm running centos 6 64bit server (command line only)
this command works fine in a terminal: Quote:
Quote:
|
Code:
SCRIPT=$(ffmpeg -i "rtmp://<ip-camera>" \ |
thanks for your response: good news and bad news:
your command works in that it starts ffmpeg but it causes a long scroll in the console and the stream.log file is not touched. When the script works properly the console looks like this: Quote:
but now it looks like this: Quote:
|
I would hazard a guess that whatever it is you are snipping is probably causing some problems.
May I ask why we are either storing the command in a variable (your first example) or capturing the output of the command into your variable (the example from next post)? Is there an issue with simply executing it where it is needed within the script? Are you using either of the above methods because your script is calling this command several times? As a third alternative, if being called multiple times, perhaps you should place it in a function?? |
thanks but I hardly understand any of what you said, my knowledge isn't that good. I don't know what a variable is, or a function. I'm capturing the log with tail -f because it's the only way to confirm the script is working and ffmpeg is actually runnng, which at the moment it isn't. If it's not possible to wrap long lines within a bash script then ok but I don't know what can be done and what can't.
|
Can you post the whole script in a pastebin? http://paste.ubuntu.com/
Seeing the whole thing will help troubleshoot it, without causing problems further down the lines. |
thanks for your response. This is the whole script - /etc/init.d/stream
Quote:
|
Most likely you have a quoting failure...
It is one of the difficulties of shell programming - when the parameters get long, and you try to pass the entire string as a parameter to something else that is going to interpret the string.. It is hard to get right. One thing you can do to test things is to run it manually: sh -vx stream start >& errorlog This should fail as you have seen, but the recording in "errorlog" will show each step of the script, AND show how each line/variable gets expanded. |
@jpollard: I think you misunderstand. The command works, that's not the problem. The essence of this topic is how to break the long line down in the script into shorter lines so it all fits in the console window and so it still works when it's run.
|
You have said this script works, I am not sure how as there are a number of typos and even a variable which does not exist but is called (namely PIDNAME).
So i will point out that all startup scripts are generally run as root so not only do I not see the point of your RUNAS variable, I see no point to the entire call to su? If you think about it, if you were really calling su to change yourself to root, you would need to enter the password, which would seem mute at startup as there would be nowhere to capture this information. Finally, jpollard does not misunderstand and is exactly correct ... ie apart from escaping the end of the line to create the continuation, how you have quoted is the biggest issue. To demonstrate using your original example: Code:
SCRIPT="ffmpeg -i "rtmp://<ip-camera>" \ code is not quoted at all, point in case - the last set of quotes is at the end of everything with nothing between them Were it quoted correctly: Code:
SCRIPT="ffmpeg -i 'rtmp://<ip-camera>' \ |
Code:
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!" |
At least two...
1. su isn't needed to run a root process (it already is). 2. The CMD gets turned into multiple redirects... and the "LOGFILE" may not be a log file... (remember, the $SCRIPT is expanded.. As the "CMD" and "LOGFILE" environment variables are expanded for the assignment there can easily be more quoting peculiarities - things you expect to be quoted won't be, things you didn't expect might be... And when SCRIPT is expanded you again get quoting reinterpreted... It is very very hard to get such quoting right. It would be much simpler to do: Code:
I have always found this form simplifies handling the quoting, and allows each option to be examined independently. |
@grail thankyou for your help, you solved it. Using ' instead of " worked and I am now able to break this long command down into several lines in the script, I can see the whole string clearly and the command works when the script is started.
|
Please use the Thread Tools to mark the question as SOLVED
|
All times are GMT -5. The time now is 04:58 PM. |