Solved

Linux Script

Posted on 2011-02-23
6
263 Views
Last Modified: 2012-05-11
I am writing a linux script to automate a few commands I wish to run on my machine.  My question is this:

I have about 5 -10 commands I need to run in the script.  But there are a few commands that I need it to open up a new shell and run them seperately from the others.

Example:

Commands 1-4 in one shell
5-6 in another shell
7-9 in a third shell for a total of 3 shells when the script completes.

How do I tell the script to open a new shell when running one of the specific commands?  Is that possible?
0
Comment
Question by:cbur2107
  • 2
  • 2
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 34964911
How about:

(command1;command2;command3;command4) &
(command5;command6) &
(command7;command8;command9)&

this starts off three subshells in the background.
0
 
LVL 1

Author Comment

by:cbur2107
ID: 34964976
i will give that a try and let you know.

Thanks.

0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 34970716
simon3270's should work fine as long as there is no inter-dependence between results or actions from or between shell1 shell2 and shell3. obviously command1;command2;command3 and command4 will run sequentially but you may run into the case where command5 thru command89 finish ahead of command1.  By putting the three shells in background all three will start executing immediately.  if that is what you want then it should work fine.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:cbur2107
ID: 34972459
So how do you tell the script to start one command AFTER another rather than all executing immediately...?
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 34972979
you could have the last line of script one call script two and the last line of script 2 call script three.
0
 
LVL 19

Assisted Solution

by:simon3270
simon3270 earned 500 total points
ID: 34975393
or just miss out the ampersands.

(command1;command2;command3;command4)
(command5;command6)
(command7;command8;command9)

will run commands 1, 2, 3 and 4, one after the other, in one shell.  Then when command 4 finishes, that first shell finishes.  Command 5 followed by command 6 then runs in a second shell.  That shell then finishes and commands 7, 8 and 9 run in a third separate shell.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now