In my Mac, how do I write a script that can do this?
- Open "terminal".
- In that terminal, "ssh myserver"
- Open a new "tab" inside the terminal.
- In that tab, "ssh myserver2"
Then, how would I run this script?
Open /Applications/Utilities/AppleScript Editor.app
and enter the following:
tell application "Terminal"
activate
tell application "System Events"
keystroke "t" using command down # new tab
keystroke "ssh myserver"
key code 36 # press enter
keystroke "t" using command down # new tab
keystroke "ssh myserver2"
key code 36 # press enter
end tell
end tell
Save as script or application. Anytime you execute, Terminal will be brought to front (started if necessary), and two new tabs will be created for your SSH sessions.
In this answer I outlined how to check whether a window is already open (without an application running) to prevent opening one tab/window too many.
You can create a Window Group to make it convenient to recreate windows and tabs, and you can use Settings profiles to issue ssh commands when windows/tabs are created.
Now, whenever you want to recreate that window and start the ssh sessions, choose Window > Open Window Group > [your group].
You can also tell Terminal to open the window group every time you start Terminal (Terminal > Preferences > Startup > On startup, open: > Window group:).
Use iTerm 2 (scroll down to profiles)
Profiles
Many settings are stored in profiles. A profile is a named collection of settings, and you can have as many of them as you like. Most users only have one profile, but if you find that you often connect to different servers, they may be useful for you. A key feature of a profile is that you can associate a command with it that is run when it begins. For instance, if you often ssh to a particular host, you could create a profile with the command "ssh example.com" to automate that process.