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.
Depends on what you mean by "show x,y,z when executing w".
If you don't redirect input/output from/to appropriate files, then all of that input/output will be ATTEMPTED from the same command window. Which means you don't know which application may have requested input (and hanging all the others), or which output belongs to which command...
Now sometimes the output doesn't matter - the case of status messages from various commands (such as scp, tar ...), but can get confusing if running the same command with different contexts (like creating multiple tar files from different directories in parallel).
In more common terms, these are just other processes, organized such that the command shell that started them is known to be the parent process.
Usually the term "subshell" is used within a shell script where things like loops, functions, and such may get run as separate processes, but don't have to be.
The commands here are files/scripts prefixed with nohup and suffixed with an ampersand
(nohup sh scriptname_w.sh &);(nohup sh scriptname_x.sh &);(nohup sh scriptname_y.sh &);(nohup sh scriptname_z.sh &);
specifically in the command above will they be sequentially executed?
I was not able to run them without the parenthesis, what I received was a "syntax error near ';'"
This worked when I created two scripts abc.sh and def.sh,
abc.sh created a file using touch command
and def.sh moves that file to a directory above the current directory
mv abc.txt ../
This worked fine-sequentially.So I used the same to run my prod scripts.
Question: Does this work sequentially?
Am I required to write the ampersand outside the bracket as well/both inside and outside/only outside.
What options do I have with position of ampersand?
and lastly when we do a
cd somedir;ls -al
it works just fine, what makes the nohup sh scriptname.sh ampersand to not follow the usual thing and show a syntax error
Last edited by firstname.lastname@example.org; 03-16-2014 at 08:59 PM.
No, as soon as the first command is put into the background, the shell proceeds to interpret and execute the second - which is also put into the background.
The & symbol in this context puts the preceding command into the background. It also functions as a command terminator.
If you wanted these to run serially that is also possible - but you do it by putting the entire command line inside parenthises (to group the string), with each command separated by a ";" and then put a single & at the end:as in (cmd1; cmd2; cmd3) &
Alternatively you can use: bash -c 'cmd1; cmd2; cmd3' &
which accomplishes the same thing. Redirection is also possible: bash -c 'cmd1; cmd2; cmd3' >log 2>&1 &
The "2>&1" construct causes stderr to be redirected to the same file as stdout. This redirection works with the () construct as well.
The "nohup" command separates the process that executes the command(s) from the controlling terminal. This is required for some shells, and is a good idea for others - it allows you to log out and the commands will continue to run. This isn't always required (it is up to the specific shell as to whether background processes are detached or not - and it also depends on whether all the stdin/stdout/stderr has been redirected from the terminal.
Last edited by jpollard; 03-16-2014 at 10:01 PM.
Reason: removed accidental double post
It looks like this(whether execution of the commands is serial) is contingent to the task.
Please give me an example other than the one I am facing where it is not serial.
Sorry to bother you.
Feel absolutely free to not provide an example.
(nohup sh script_w.sh;nohup sh script_x.sh;nohup sh script_y.sh) &
This is what you suggested right?
Thanks for your time.