I need shell script help
- Login o registrati per inviare commenti
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?
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?
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
It could simply be:
#!/bin/sh
A &
sleep 5
B
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
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
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.
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.
Those are just a few freely available examples:
http://tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Guide.pdf
http://tldp.org/HOWTO/pdf/Bash-Prog-Intro-HOWTO.pdf
http://tldp.org/LDP/abs/abs-guide.pdf
- Login o registrati per inviare commenti