2011-01-13 25 views
2

我下面這個教程:https://help.ubuntu.com/community/EC2StartersGuide幫助與EC2-API工具的Ubuntu

要啓動一個實例,我們可以運行:

ec2-run-instances ami-xxxxx -k ec2-keypair 

然後運行:

ec2-describe-instances 

這獲取實例的外部主機名。

後來,爲SSH,你運行:

ssh -i /path/to/ec2-keypair.pem [email protected]<external-host-name> 

這工作得很好,但這裏是我的問題:

我如何在bash腳本自動化此?我能否以某種方式解析從「ec2-describe-instances」返回的響應?

回答

0

我不知道是什麼的ec2-describe-instances輸出的樣子,但如果是單純的主機名,那麼你應該能夠做到:

host=$(ec2-describe-instances) 
ssh -i /path/to/ec2-keypair.pem [email protected]$host 
+0

它不是。我發現http://stackoverflow.com/questions/2644742/getting-id-of-an-instance-newly-launched-with-ec2-api-tools和http://www.thegeekstuff.com/2010/01/ awk-introduction-tutorial-7-awk-print-examples /相當有幫助。我已經使用了大約6個月的Linux,並且最近纔開始學習bash腳本。 – user94154 2011-01-13 21:33:54