2

Heres what I'm trying to do. I have 4 shell scripts. Script 1 needs to be run first, then 2, then 3, then 4, and they must be run in that order. Script 1 needs to be running (and waiting in the background) for 2 to function properly, however 1 takes about 3 seconds to get ready for use. I tried doing ./1.sh & ./2.sh & ./3.sh & ./4.sh, but this results in a total mess,since 2 starts requesting things from 1 when 1 is not ready yet. So, my question is, from one shell script, how do I get it to start script 1, wait like 5 seconds, start script 2, wait like 5 seconds, etc. without stopping any previous scripts from running (i.e. they all have to be running in the background for any higher numbered script to work). Any suggestions would be much appreciated!

2 Answers 2

2

May I introduce you to the sleep command?

./1.sh & sleep 5
./2.sh & sleep 5
./3.sh & sleep 5
./4.sh
Sign up to request clarification or add additional context in comments.

Comments

0
#!/bin/sh
./1.sh &; sleep 5;./2.sh &; sleep 5; ./3.sh &; sleep 5; ./4.sh

1 Comment

You can use EITHER & OR ; to terminate a command (with different implications); using BOTH will result in a syntax error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.