I need shell script help

8 Antworten [Letzter Beitrag]
Sachin
Offline
Beigetreten: 06/02/2012

I want to run few apps that will start one after another after a specific time interval. I am currently using the following script:


#!/bin/sh
# run B 5 seconds later, but without blocking the rest of the script
command "/usr/bin/A" &
sleep 5 && command "/usr/bin/B"

Is it correct?
Do I have to make improvements?

SirGrant

I am a member!

I am a translator!

Offline
Beigetreten: 07/27/2010

Can you explain what the programs do? Does A have to finish before B starts? Is it ok to send these programs to the background to finish their jobs?

Sachin
Offline
Beigetreten: 06/02/2012

I use these three softwares mostly and everytime I have to start them one by one in the following order:
1. Qjactctl
2. Qsynth
3. Rosegarden

Magic Banana

I am a member!

I am a translator!

Offline
Beigetreten: 07/24/2010

It could simply be:
#!/bin/sh

A &
sleep 5
B

Darksoul71
Offline
Beigetreten: 01/04/2012

Essentially it is correct. For sleeping 5 seconds you need to call "sleep 5s" altough the number given to sleep is treated as second per default.

& is used to send each programm in the background prior launching the next programm.

I would only use && to chain the command sequence if it is likely that calling on program fails.

My version would look like this:

#!/bin/sh
/usr/bin/foo &
sleep 5s
/usr/bin/baar

Of course you could make this a bit more sophisticated by waiting for the process of /usr/bin/foo prior launching /usr/bin/baar.

HTH,
Holger

Sachin
Offline
Beigetreten: 06/02/2012

Thank you all for the help.
I have finally got what i needed.

I guess i should also read bash manual it will be useful

SirGrant

I am a member!

I am a translator!

Offline
Beigetreten: 07/27/2010

You could also maybe pick up a used book. My father gave me a old Unix book (yes, I am aware GNU means GNU is not unix) from 1995 and while some of the information is depreciated a lot is very useful.

Magic Banana

I am a member!

I am a translator!

Offline
Beigetreten: 07/24/2010

The manual is a reference but not a didactic material. You can start with reading Introduction to the Command Line, then Bash Guide for Beginners and, if you want to become an expert, the Advanced Bash-Scripting Guide.

Darksoul71
Offline
Beigetreten: 01/04/2012