0

In my Desktop/src/ directory I have shell scripts that I want to run in a series and some must run after the first has completed running and all the commands must run on new terminal window. I am working on Mac OS X.

So far I have tried the following code

osascript<<EOF
tell application "System Events"
tell process "Terminal" to keystroke "n" using command down
end

tell application "Terminal"
activate
do script with command "cd Desktop/src/ && sh startRM1.sh"
end tell

tell application "Terminal"
activate
do script with command "cd Desktop/src/ && sh startRM2.sh"
end tell

tell application "Terminal"
activate
do script with command "cd Desktop/src/ && sh startRM3.sh"
end tell
EOF

The problem is that startRM1.sh takes a little time to start, and startRM2.sh, startRM3.sh start straight away and crash since they must wait for startRM1.sh to complete All three of them must start in new window.

Edit: startRM1.sh is a server which keeps running; therefore the control never goes to the second step.

problem solved using following

osascript<<EOF
tell application "System Events"
tell process "Terminal" to keystroke "n" using command down
end

tell application "Terminal"
activate
do script with command "cd Desktop/src/ && sh startRM1.sh" in window 1
end tell

tell application "Terminal"
activate
do script with command "sleep 5 && cd Desktop/src/ && sh startRM2.sh"
end tell

tell application "Terminal"
activate
do script with command "sleep 5 && cd Desktop/src/ && sh startRM3.sh"
end tell
EOF
M_J
  • 61
  • 10
  • 1
    How can you tell when startRM1.sh has started, and what do you mean by started ? –  Jun 04 '14 at 13:31
  • Why do you want the server started by `startRM1.sh` to have its own terminal window? Normally, you run servers in the background with the output going to a log file. And, as Jidder asked, how do you know when it is safe to run `startRM2.sh` or `startRM3.sh`? – Jonathan Leffler Jun 04 '14 at 13:38
  • When startRM1.sh runs, it displays the server is running context, and it also registers the rmi registry that is looked up by startRM2.sh and startRM3.sh. I have solved the problem – M_J Jun 04 '14 at 13:39
  • I added your comment about 'therefore the control never goes to the second step' to the question, but that seems to contradict the observation that 'startRM2.sh, startRM3.sh start straight away and crash'. _[…seconds later…]_ Oh, you've solved your problem. – Jonathan Leffler Jun 04 '14 at 13:39
  • @JonathanLeffler i want to run server on a new terminal for testing, i am trying to check the functionality and must display the workings on the terminal. I have solved this by adding sleep in-front of the programs that follow startRM1.sh – M_J Jun 04 '14 at 13:43
  • I would consider the inability to wait for the appropriate resource to become available a bug in `startRM2.sh` and `startRM3.sh`. – chepner Jun 04 '14 at 16:14

1 Answers1

0

Create a shellscript that is your start point.

You can create a .sh file that would could call:

source mynewShell.sh

and in that, it will have all the other files, called in the orders you need, and any config data etc

Fallenreaper
  • 10,222
  • 12
  • 66
  • 129
  • startRM1.sh is a server which keeps running i forgot to add that, therefore the control never goes to the second step. I tried your solution but since RM1.sh being a server it never goes to second step. – M_J Jun 04 '14 at 13:08