Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
it's a long single line however I want to put it into a startup script in /etc/init.d/ and I want to wrap the lines within the console window but I can't get it to work. I've seen other commands work ok with a '/' on the end of each line but it doesn't work for me. This is the first part of the script:
I'm using putty on a windows 7 machine to create a terminal for access to the server. I've googled about this but I can't find the correct syntax to enable me to break and wrap the lines of this long command. The log keeps saying "Trailing options were found on the commandline". What am I doing wrong?
Last edited by tonj; 05-17-2014 at 10:43 AM.
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:
# /etc/init.d/stream start
and if I tail /var/log/stream.log I can see details of the process running
but now it looks like this:
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.
if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then
echo 'Service already running' >&2
echo 'Starting serviceâ€¦' >&2
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
su -c "$CMD" $RUNAS > "$PIDFILE"
echo 'Service started' >&2
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
echo 'Service not running' >&2
echo 'Stopping serviceâ€¦' >&2
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
echo 'Service stopped' >&2
echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
if [ "$SURE" = "yes" ]; then
rm -f "$PIDFILE"
echo "Notice: log file is not be removed: '$LOGFILE'" >&2
update-rc.d -f stream remove
rm -fv "$0"
@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:
Here I have colour coded all the matching sets of double quotes you have used. If you look at where you see the colour first appearing and then where it ends, you will notice that a great deal of your
code is not quoted at all, point in case - the last set of quotes is at the end of everything with nothing between them
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...
@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.