Google AdSense

Thursday, January 3, 2013

Using Applescript to lauch several terminal tabs with ssh

This is an applescript that will launch your terminal and go ahead and get you logged into several ssh sessions in tabs. I wrote this...or rather cannabalized somebody else's script, when I was a sys admin and programmer, I needed to be sshed into several machines at the beginning of work. I thought that if I used scripts like this I would end up saving time in the long run.

This actually turned out not to be true, but through no fault of my own. It turned out that the e-commerce book store that I was working for was getting over ninety percent of there sells from a single book, that relied on a single link referral. And they pulled the link referral because the place that I worked for, was constantly late delivering the book. Never trust a company with Christian in their name.

You will need to change "root" to be your user and the domain names to be your domain names. If you have ssh keys set up, you should be good to go. Otherwise you will have to manually type or paste your password in.

Occasionally a ball-peen hammer hits me in the head and I forget how to set up ssh keys, if this happened to you, you can use this link to remind yourself. HowTo Ssh Keys

set user to "root"
set theHost to "mechanicalpinata.com"

activate application "Terminal"

tell application "System Events"
 tell process "Terminal"
  keystroke "t" using command down
 end tell
end tell

delay 1 -- it seems we need this

tell application "Terminal"
 do script "ssh " & user & "@" & theHost in the last tab of window 1
end tell

set user to "root"
set theHost to "YourOtherDomainNameOrIP.com"

activate application "Terminal"

tell application "System Events"
 tell process "Terminal"
  keystroke "t" using command down
 end tell
end tell

delay 1 -- it seems we need this

tell application "Terminal"
 do script "ssh " & user & "@" & theHost in the last tab of window 1
end tell

No comments: