connect
Connects.
connect <command line parameters>
Remarks
Connects the window the macro is running in to the destination given by <command line parameters>. <command line parameters> uses the same format as the Tera Term Mac command line (the SSH options can also be used).
If the macro is not linked to a window (after unlink or closett, or after the window was closed), this command opens a new window, links it to the macro and connects in that window.
If the macro has already been linked to a window and the window is not connected to the host, this command causes the window to connect to the host specified by <command line parameters>. If no destination is given, the connection dialog is shown.
If the macro has already been linked to a window and the window has already been connected to the host, this command is ignored.
The macro does not go on to the next line until the connection is made (or fails). As a result of this command, the system variable "result" is set to one of the following values depending on the link and connection status:
| Value | Status |
|---|---|
| 0 | The macro is not linked to a window. |
| 1 | Connection to the host has not been made, but the macro is linked to a window. |
| 2 | Both connection and link have been made. |
To test the current link and connect status before executing the "connect" command, use the "testlink" command.
Communication commands except "connect", "cygconnect" and "testlink" can not be executed before the link is established.
Connection method
These types of connection can be established from a macro:
- Telnet connection (port 23)
- SSH connection (port 22)
- Serial port connection
Telnet connections
connect 'myserver:23 /nossh /T=1'
connect 'myserver:23'
Using /nossh is strongly recommended. Without this parameter the connection uses the same method (telnet or SSH) as in the last saved settings. In case it was SSH, your macro will try to connect via SSH and will eventually fail.
Using /T=1 is recommended. Without this parameter the connection uses the value of 'Telnet' in the settings. When the Telnet value is off, telnet negotiation is not done and the session may not work well.
SSH connections
SSH connections use the macOS ssh command (OpenSSH) with SSH2.
connect 'myserver /ssh'
connect 'myserver /ssh /2'
connect 'myserver /ssh /auth=password /user=username /passwd=password'
connect 'myserver /ssh /auth=publickey /user=username /passwd=password /keyfile=private-key-file'
connect 'myserver /ssh /auth=challenge /user=username /passwd=password'
These ways pass username and password directly from the macro, so the password does not have to be typed. /auth=password is password authentication, /auth=publickey is public key authentication (/passwd= is the passphrase of the private key), and /auth=challenge is challenge-response authentication. Do not replace the word 'password' or 'publickey' in /auth= with the actual password.
connect 'myserver /ssh /auth=pageant /user=username'
This way passes username from the macro and uses public key authentication with the keys in ssh-agent etc.
connect 'myserver /ssh /auth=password /user=username /ask4passwd'
connect 'myserver /ssh /auth=publickey /user=username /ask4passwd /keyfile=private-key-file'
connect 'myserver /ssh /auth=challenge /user=username /ask4passwd'
These ways pass username and authentication method directly from the macro, and the popup asks for password.
Serial port connections
connect '/C=x'
connect '/C=/dev/cu.usbserial-XXXX'
Here x is the position of the port in the list of Mac serial ports (counted from 1). For example, to connect via the first port, use connect '/C=1'. You can also give the device directly, e.g. /C=/dev/cu.usbserial-XXXX.
Examples
; No destination (the connection dialog is shown) connect '' ; Timeout will occur if connection does not succeed within five seconds. connect 'myserver /timeout=5' ; Open telnet session connect 'myserver:23 /nossh' ; Open SSH session connect 'myserver /ssh' ; Open SSH session and do not prompt for user name and password connect 'myserver /ssh /auth=password /user=username /passwd=password' ; Open SSH session, do not prompt for user name and password, and use private key file connect 'myserver /ssh /auth=publickey /user=username /passwd=password /keyfile=private-key-file' ; Connect with public key authentication using the keys in ssh-agent, ; and do not prompt for user name and password. connect 'myserver /ssh /auth=pageant /user=username' ; Open serial port connection. x is the position in the list of serial ports (from 1). connect '/C=x' CommandLine = '111.111.11.11' connect CommandLine
; Sample macro for Tera Term ; Telnet login ; connect to the host (telnet) connect 'myhost.mydomain' ; set username UsernamePrompt = 'Username:' Username = 'MYNAME' PasswordPrompt = 'Password:' ; get password from file getpassword 'password.dat' 'mypassword' Password ; login wait UsernamePrompt sendln Username wait PasswordPrompt sendln Password ; OK, auto login complete.
; sample macro of Tera Term ; ; File: ssh2login.ttl ; Description: auto login with SSH2 protocol ; Environment: generic username = 'nike' hostname = '192.168.1.3' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; msg = 'Enter password for user ' strconcat msg username passwordbox msg 'Get password' msg = hostname strconcat msg ':22 /ssh /auth=password /user=' strconcat msg username strconcat msg ' /passwd=' strconcat msg inputstr connect msg
Note
- In these examples parameters shown with Italic font have to be replaced with their actual values.
- A user's password can include space characters. If the password includes the space character, a user should put the password in quotations by using `"' character. Also, if the password includes the " character, a user should write the " two times.
- Please remember that entering actual username and password in a macro will cause them to be stored as an open text and it is your responsibility to keep such macro is secure location.
- When a user re-connect the remote host soon after disconnecting the server, a user could not connect the server. For more detail, refer to "here".
- Please refer to Notes on Specifying a Password of the SSH command line.