[英]How to run shell scripts in series in terminal windows in Mac OS X
在我的Desktop/src/
目錄中,我有一系列要運行的shell腳本,其中一些必須在第一個腳本運行完畢后運行,並且所有命令都必須在新的終端窗口上運行。 我正在Mac OS X上工作。
到目前為止,我已經嘗試了以下代碼
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
問題在於,startRM1.sh需要花費一些時間來啟動,startRM2.sh,startRM3.sh立即啟動並崩潰,因為它們必須等待startRM1.sh完成。所有這三個都必須在新窗口中啟動。
編輯:startRM1.sh是保持運行的服務器; 因此控制永遠不會進入第二步。
使用以下問題解決了問題
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
創建一個shellscript,這是您的起點。
您可以創建一個.sh文件,該文件可以調用:
source mynewShell.sh
然后,它將包含所有其他文件(按需要的順序調用)以及所有配置數據等
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.